Package de.trustable.ca3s.core.web.rest
Class AccountResource
- java.lang.Object
-
- de.trustable.ca3s.core.web.rest.AccountResource
-
@RestController @RequestMapping("/api") public class AccountResource extends ObjectREST controller for managing the current user's account.
-
-
Constructor Summary
Constructors Constructor Description AccountResource(UserRepository userRepository, UserService userService, MailService mailService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateAccount(String key)GET /activate: activate the registered user.voidchangePassword(PasswordChangeDTO passwordChangeDto)POST /account/change-password: changes the current user's password.voidfinishPasswordReset(KeyAndPasswordVM keyAndPassword)POST /account/reset-password/finish: Finish to reset the password of the user.UserDTOgetAccount()GET /account: get the current user.StringisAuthenticated(javax.servlet.http.HttpServletRequest request)GET /authenticate: check if the user is authenticated, and return its login.voidregisterAccount(@Valid ManagedUserVM managedUserVM)POST /register: register the user.voidrequestPasswordReset(String mail)POST /account/reset-password/init: Send an email to reset the password of the user.voidsaveAccount(@Valid UserDTO userDTO)POST /account: update the current user information.
-
-
-
Constructor Detail
-
AccountResource
public AccountResource(UserRepository userRepository, UserService userService, MailService mailService)
-
-
Method Detail
-
registerAccount
@PostMapping("/register") @ResponseStatus(CREATED) public void registerAccount(@Valid @RequestBody @Valid ManagedUserVM managedUserVM)POST /register: register the user.- Parameters:
managedUserVM- the managed user View Model.- Throws:
InvalidPasswordException-400 (Bad Request)if the password is incorrect.EmailAlreadyUsedException-400 (Bad Request)if the email is already used.LoginAlreadyUsedException-400 (Bad Request)if the login is already used.
-
activateAccount
@GetMapping("/activate") public void activateAccount(@RequestParam("key") String key)GET /activate: activate the registered user.- Parameters:
key- the activation key.- Throws:
RuntimeException-500 (Internal Server Error)if the user couldn't be activated.
-
isAuthenticated
@GetMapping("/authenticate") public String isAuthenticated(javax.servlet.http.HttpServletRequest request)GET /authenticate: check if the user is authenticated, and return its login.- Parameters:
request- the HTTP request.- Returns:
- the login if the user is authenticated.
-
getAccount
@GetMapping("/account") public UserDTO getAccount()GET /account: get the current user.- Returns:
- the current user.
- Throws:
RuntimeException-500 (Internal Server Error)if the user couldn't be returned.
-
saveAccount
@PostMapping("/account") public void saveAccount(@Valid @RequestBody @Valid UserDTO userDTO)POST /account: update the current user information.- Parameters:
userDTO- the current user information.- Throws:
EmailAlreadyUsedException-400 (Bad Request)if the email is already used.RuntimeException-500 (Internal Server Error)if the user login wasn't found.
-
changePassword
@PostMapping(path="/account/change-password") public void changePassword(@RequestBody PasswordChangeDTO passwordChangeDto)POST /account/change-password: changes the current user's password.- Parameters:
passwordChangeDto- current and new password.- Throws:
InvalidPasswordException-400 (Bad Request)if the new password is incorrect.
-
requestPasswordReset
@PostMapping(path="/account/reset-password/init") public void requestPasswordReset(@RequestBody String mail)POST /account/reset-password/init: Send an email to reset the password of the user.- Parameters:
mail- the mail of the user.- Throws:
EmailNotFoundException-400 (Bad Request)if the email address is not registered.
-
finishPasswordReset
@PostMapping(path="/account/reset-password/finish") public void finishPasswordReset(@RequestBody KeyAndPasswordVM keyAndPassword)POST /account/reset-password/finish: Finish to reset the password of the user.- Parameters:
keyAndPassword- the generated key and the new password.- Throws:
InvalidPasswordException-400 (Bad Request)if the password is incorrect.RuntimeException-500 (Internal Server Error)if the password could not be reset.
-
-