|
|
|
|
@@ -70,34 +70,34 @@ public class UserController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @PostMapping("/change-password")
|
|
|
|
|
// @PreAuthorize("hasAuthority('UPDATE_USER')")
|
|
|
|
|
// public ResponseEntity<?> changeUserPassword(@RequestBody Login login) {
|
|
|
|
|
// try {
|
|
|
|
|
// userService.updatePassword(login.getUsername(), login.getPassword());
|
|
|
|
|
// return new ResponseEntity<>(
|
|
|
|
|
// new ApiResponse<>(true, "Votre mot de passe à été modifiée avec succès."),
|
|
|
|
|
// HttpStatus.OK
|
|
|
|
|
// );
|
|
|
|
|
// } catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
|
|
|
// logger.error(e.getLocalizedMessage());
|
|
|
|
|
// return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
|
|
|
// } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
|
|
|
// FileStorageException e) {
|
|
|
|
|
// logger.error(e.getLocalizedMessage());
|
|
|
|
|
// return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
|
|
|
// } catch (NullPointerException e) {
|
|
|
|
|
// logger.error(e.getLocalizedMessage());
|
|
|
|
|
// return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// logger.error(e.getLocalizedMessage());
|
|
|
|
|
// return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/change-password")
|
|
|
|
|
@PreAuthorize("hasAuthority('UPDATE_USER')")
|
|
|
|
|
public ResponseEntity<?> changeUserPassword(@RequestBody Login login) {
|
|
|
|
|
try {
|
|
|
|
|
userService.updatePassword(login.getUsername(), login.getPassword());
|
|
|
|
|
return new ResponseEntity<>(
|
|
|
|
|
new ApiResponse<>(true, "Votre mot de passe à été modifiée avec succès."),
|
|
|
|
|
HttpStatus.OK
|
|
|
|
|
);
|
|
|
|
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
|
|
|
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
|
|
|
|
FileStorageException e) {
|
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/change-my-password")
|
|
|
|
|
@PreAuthorize("hasAuthority('UPDATE_USER')")
|
|
|
|
|
@PreAuthorize("hasAuthority('CHANGE_MY_PASSWORD')")
|
|
|
|
|
public ResponseEntity<?> changeMyPassword(@CurrentUser UserPrincipal currentUser, @RequestBody Login login) {
|
|
|
|
|
try {
|
|
|
|
|
User user = currentUser.getUser() ;
|
|
|
|
|
|