diff --git a/src/main/java/org/ntlab/tampoposerver/resources/UsersResource.java b/src/main/java/org/ntlab/tampoposerver/resources/UsersResource.java index 94e2190..f8a287b 100644 --- a/src/main/java/org/ntlab/tampoposerver/resources/UsersResource.java +++ b/src/main/java/org/ntlab/tampoposerver/resources/UsersResource.java @@ -51,7 +51,7 @@ } //@Path("/{uid}/..")などパスを指定する - //アカウントの基本情報 + //アカウントの基本情報 テストパス @GET @Produces(MediaType.APPLICATION_JSON) /*関数の名前を適切なものに変更する @@ -68,10 +68,10 @@ } - //新規アカウントを作る + //新規アカウントを作る テストパス @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response createUser(@FormParam("user_id") String userId, @FormParam("password") String password) { + public Response createUser(@FormParam("user-id") String userId, @FormParam("password") String password) { //ユーザーがいるか調べる User user = userRepository.getUser(userId); @@ -88,11 +88,11 @@ } - //単一アカウントの情報を返す + //単一アカウントの情報を返す テストパス @GET - @Path("/{userId}") + @Path("/{user-id}") @Produces(MediaType.APPLICATION_JSON) - public Response getUser(@PathParam("userId") String userId) { + public Response getUser(@PathParam("user-id") String userId) { //取得 User user = userRepository.getUser(userId); //存在の確認 @@ -102,11 +102,11 @@ return Response.ok(user, MediaType.APPLICATION_JSON).build(); } - //ユーザの削除 ok + //ユーザの削除  テストパス @DELETE //deleteはquery parameter - @Path("/{userId}") - public Response deleteUser(@PathParam("userId") String userId, @QueryParam("token") String token) { + @Path("/{user-id}") + public Response deleteUser(@PathParam("user-id") String userId, @QueryParam("token") String token) { //取得 User user = userRepository.getUser(userId); //存在チェック @@ -132,11 +132,11 @@ } - //ログイン + //ログイン テストパス @POST - @Path("/{userId}/login") + @Path("/{user-id}/login") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response login(@PathParam("userId") String userId, @FormParam("password") String password) { + public Response login(@PathParam("user-id") String userId, @FormParam("password") String password) { //存在チェック User user = userRepository.getUser(userId); @@ -164,11 +164,11 @@ } - //アカウントのニックネームの取得 ok + //アカウントのニックネームの取得 テストパス @GET - @Path("/{userId}/name") + @Path("/{user-id}/name") @Produces(MediaType.APPLICATION_JSON) - public Response getName(@PathParam("userId") String userId) { + public Response getName(@PathParam("user-id") String userId) { //取得 User user = userRepository.getUser(userId); //存在チェック @@ -181,11 +181,11 @@ return Response.ok(user.getName(), MediaType.APPLICATION_JSON).build(); } - //ニックネームの変更 + //ニックネームの変更 テストパス @PUT - @Path("/{userId}") + @Path("/{user-id}") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response updateName(@PathParam("userId") String userId, @FormParam("new_name") String newName, @FormParam("token") String token) { + public Response updateName(@PathParam("user-id") String userId, @FormParam("new-name") String newName, @FormParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { @@ -210,23 +210,31 @@ } - //単一アカウントのパスワードの取得 ok + //単一アカウントのパスワードの取得 テストパス @GET - @Path("/{userId}/password") + @Path("/{user-id}/password") @Produces(MediaType.APPLICATION_JSON) - public Response getPassword(@PathParam("userId") String userId, @QueryParam("token") String token) { + public Response getPassword(@PathParam("user-id") String userId, @QueryParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } + + if (token == null || !token.equals(user.getToken())) { + throw new WebApplicationException( + Response.status(Response.Status.FORBIDDEN) + .entity("認証失敗") + .build() + ); + } return Response.ok(user.getPassword(), MediaType.APPLICATION_JSON).build(); } - //指定されたIDのパスワードを変更する + //指定されたIDのパスワードを変更する テストパス @PUT - @Path("/{userId}/password") + @Path("/{user-id}/password") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response updatePassword(@PathParam("userId") String userId, @FormParam("new_password") String newPassword) { + public Response updatePassword(@PathParam("user-id") String userId, @FormParam("new-password") String newPassword, @QueryParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { @@ -237,6 +245,13 @@ ); } + if (token == null || !token.equals(user.getToken())) { + throw new WebApplicationException( + Response.status(Response.Status.FORBIDDEN) + .entity("認証失敗") + .build() + ); + } //パスワードのアップデート user.setPassword(newPassword); @@ -245,11 +260,11 @@ } - //単一アカウントのemailの取得 + //単一アカウントのemailの取得 テストパス @GET - @Path("/{userId}/email") + @Path("/{user-id}/email") @Produces(MediaType.APPLICATION_JSON) - public Response getEmail(@PathParam("userId") String userId) { + public Response getEmail(@PathParam("user-id") String userId) { User user = userRepository.getUser(userId); if (user == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); @@ -257,11 +272,11 @@ return Response.ok(user.getEmail(), MediaType.APPLICATION_JSON).build(); } - //指定されたIDのemailを変更する + //指定されたIDのemailを変更する テストパス @PUT - @Path("/{userId}/email") + @Path("/{user-id}/email") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response updateEmail(@PathParam("userId") String userId, @FormParam("new_email") String newEmail, @FormParam("token") String token) { + public Response updateEmail(@PathParam("user-id") String userId, @FormParam("new_email") String newEmail, @FormParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { @@ -286,11 +301,11 @@ } - //指定されたIDのアイコンを返す + //指定されたIDのアイコンを返す テストパス @GET - @Path("/{userId}/icon") + @Path("/{user-id}/icon") @Produces(MediaType.APPLICATION_JSON) - public Response getIcon(@PathParam("userId") String userId) { + public Response getIcon(@PathParam("user-id") String userId) { User user = userRepository.getUser(userId); if (user == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); @@ -298,11 +313,11 @@ return Response.ok(user.getIcon(), MediaType.APPLICATION_JSON).build(); } - //アイコンを変更する + //アイコンを変更する テストパス @PUT - @Path("/{userId}/icon") + @Path("/{user-id}/icon") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public String updateIcon(@PathParam("userId") String userId, @FormParam("new_icon") String newIcon, @FormParam("token") String token) { + public String updateIcon(@PathParam("user-id") String userId, @FormParam("new_icon") String newIcon, @FormParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { @@ -327,11 +342,11 @@ } - //フレンド相手の情報の取得 + //フレンド相手の情報の取得 404 @GET - @Path("/{userId}/friends/") + @Path("/{user-id}/friends/") @Produces(MediaType.APPLICATION_JSON) - public Response getFriends(@PathParam("userId") String userId, @QueryParam("token") String token) { + public Response getFriends(@PathParam("user-id") String userId, @QueryParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { throw new WebApplicationException( @@ -362,11 +377,11 @@ } - //自分のペアのpid一覧(JSON)の取得 + //自分のペアのpid一覧(JSON)の取得 テストパス @GET - @Path("/{userId}/friends") + @Path("/{user-id}/friends") @Produces(MediaType.APPLICATION_JSON) - public Response getPairId(@PathParam("userId") String userId, @QueryParam("token") String token) { + public Response getPairId(@PathParam("user-id") String userId, @QueryParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { throw new WebApplicationException( @@ -391,10 +406,10 @@ } - //ペアの削除  + //ペアの削除 未テスト @DELETE - @Path("/{userId}/friends/{pairId}") - public Response deleteFriends(@PathParam("userId") String userId, @PathParam("pairId") int pairId, @QueryParam("token") String token) { + @Path("/{user-id}/friends/{pair-id}") + public Response deleteFriends(@PathParam("user-id") String userId, @PathParam("pair-id") int pairId, @QueryParam("token") String token) { User user = userRepository.getUser(userId); if (user == null) { throw new NotFoundException("IDが存在しません");