diff --git a/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java b/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java index 1904686..8d2fdb4 100644 --- a/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java +++ b/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java @@ -2,6 +2,7 @@ package org.cmh.backend.authentication.controller; import org.cmh.backend.Utils.JwtUtil; +import org.cmh.backend.Utils.JwtVerify; import org.cmh.backend.authentication.dto.*; import org.cmh.backend.authentication.model.UserHS; import org.cmh.backend.authentication.service.UserService; @@ -75,23 +76,21 @@ class AuthenticationController { } @PostMapping("/manageUserProfile") + @JwtVerify public ResponseEntity manageUserProfile(@RequestBody ManageUserProfileRequest userProfileRequest) { String username = JwtUtil.extractUsername(userProfileRequest.getToken()); - if (username != null) { - boolean succeeded = userService.updateUserProfile(username, userProfileRequest); - if (succeeded) { - return new ResponseEntity<>(HttpStatus.OK); - } + boolean succeeded = userService.updateUserProfile(username, userProfileRequest); + if (succeeded) { + return new ResponseEntity<>(HttpStatus.OK); } return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } @PostMapping("/changePassword") + @JwtVerify public ResponseEntity changePassword(@RequestBody ChangePasswordRequest changePasswordRequest) { - if (JwtUtil.isTokenValid(changePasswordRequest.getToken())) { - if (userService.changePassword(JwtUtil.extractUsername(changePasswordRequest.getToken()), changePasswordRequest)) { - return new ResponseEntity<>(HttpStatus.OK); - } + if (userService.changePassword(JwtUtil.extractUsername(changePasswordRequest.getToken()), changePasswordRequest)) { + return new ResponseEntity<>(HttpStatus.OK); } return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } diff --git a/src/main/java/org/cmh/backend/authentication/dto/ChangePasswordRequest.java b/src/main/java/org/cmh/backend/authentication/dto/ChangePasswordRequest.java index 5768562..b59142a 100644 --- a/src/main/java/org/cmh/backend/authentication/dto/ChangePasswordRequest.java +++ b/src/main/java/org/cmh/backend/authentication/dto/ChangePasswordRequest.java @@ -2,10 +2,11 @@ package org.cmh.backend.authentication.dto; import lombok.Getter; import lombok.Setter; +import org.cmh.backend.Utils.JwtRequest; @Getter @Setter -public class ChangePasswordRequest extends JwtRequest{ +public class ChangePasswordRequest extends JwtRequest { private String currentPassword; private String newPassword; } diff --git a/src/main/java/org/cmh/backend/authentication/dto/JwtRequest.java b/src/main/java/org/cmh/backend/authentication/dto/JwtRequest.java deleted file mode 100644 index 05cbacf..0000000 --- a/src/main/java/org/cmh/backend/authentication/dto/JwtRequest.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.cmh.backend.authentication.dto; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class JwtRequest { - private String token; -} - diff --git a/src/main/java/org/cmh/backend/authentication/dto/ManageUserProfileRequest.java b/src/main/java/org/cmh/backend/authentication/dto/ManageUserProfileRequest.java index 0c1f6ee..64a41a8 100644 --- a/src/main/java/org/cmh/backend/authentication/dto/ManageUserProfileRequest.java +++ b/src/main/java/org/cmh/backend/authentication/dto/ManageUserProfileRequest.java @@ -2,6 +2,7 @@ package org.cmh.backend.authentication.dto; import lombok.Getter; import lombok.Setter; +import org.cmh.backend.Utils.JwtRequest; @Getter @Setter