Minor corrections for account route.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.codiki.account;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -27,21 +29,51 @@ public class AccountController {
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
|
||||
/**
|
||||
* Log in the user in request body.
|
||||
*
|
||||
* @param pUser
|
||||
* The user to connect.
|
||||
* @param response
|
||||
* The reponse injected by Spring.
|
||||
* @return The connected user object.
|
||||
* @throws IOException
|
||||
* If credentials are bad.
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public UserDTO login(@RequestBody UserDTO pUser, HttpServletResponse response) {
|
||||
public UserDTO login(@RequestBody UserDTO pUser, HttpServletResponse response) throws IOException {
|
||||
return accountService.checkCredentials(response, pUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out the user.
|
||||
*
|
||||
* @param pRequest
|
||||
* The request injected by Spring.
|
||||
*/
|
||||
@GetMapping("/logout")
|
||||
public void logout(HttpServletRequest pRequest) {
|
||||
tokenService.removeUser(pRequest.getHeader(HEADER_TOKEN));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the user password.
|
||||
*
|
||||
* @param pPasswordWrapper
|
||||
* The object which contains the old password for verification and
|
||||
* the new password to set to the user.
|
||||
* @param pRequest
|
||||
* The request injected by Spring.
|
||||
* @param pResponse
|
||||
* The reponse injected by Spring.
|
||||
* @throws IOException
|
||||
* If the old password doesn't match to the user password in
|
||||
* database.
|
||||
*/
|
||||
@PutMapping("/changePassword")
|
||||
public boolean changePassword(@RequestBody final PasswordWrapperDTO pPasswordWrapper,
|
||||
public void changePassword(@RequestBody final PasswordWrapperDTO pPasswordWrapper,
|
||||
final HttpServletRequest pRequest,
|
||||
final HttpServletResponse pResponse) {
|
||||
return accountService.changePassword(tokenService.getAuthenticatedUserByToken(pRequest), pPasswordWrapper, pResponse);
|
||||
final HttpServletResponse pResponse) throws IOException {
|
||||
accountService.changePassword(tokenService.getAuthenticatedUserByToken(pRequest), pPasswordWrapper, pResponse);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user