Archived
Refactor some code in Java8 and transform properties file to yaml file.
This commit is contained in:
@@ -29,11 +29,21 @@ import com.fasterxml.jackson.annotation.JsonView;
|
||||
@RestController
|
||||
@RequestMapping("/api/account")
|
||||
public class AccountController {
|
||||
@Autowired
|
||||
/** Account service. */
|
||||
private AccountService accountService;
|
||||
@Autowired
|
||||
/** User service. */
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param accountService Account service.
|
||||
* @param userService User service.
|
||||
*/
|
||||
public AccountController(AccountService accountService, UserService userService) {
|
||||
this.accountService = accountService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@JsonView(View.UserDTO.class)
|
||||
@PostMapping("/login")
|
||||
public User login(@RequestBody final User pUser) throws BadCredentialsException {
|
||||
@@ -54,8 +64,6 @@ public class AccountController {
|
||||
* @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
|
||||
@@ -64,15 +72,19 @@ public class AccountController {
|
||||
*/
|
||||
@PutMapping("/changePassword")
|
||||
public void changePassword(@RequestBody final PasswordWrapperDTO pPasswordWrapper,
|
||||
final HttpServletRequest pRequest,
|
||||
final HttpServletResponse pResponse,
|
||||
final Principal pPrincipal) throws IOException {
|
||||
final Optional<User> connectedUser = userService.getUserByPrincipal(pPrincipal);
|
||||
if(connectedUser.isPresent()) {
|
||||
accountService.changePassword(connectedUser.get(), pPasswordWrapper, pResponse);
|
||||
} else {
|
||||
pResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
}
|
||||
final Principal pPrincipal) {
|
||||
int httpResponseCode = userService.getUserByPrincipal(pPrincipal)
|
||||
.map(user -> {
|
||||
try {
|
||||
return accountService.changePassword(user, pPasswordWrapper);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return HttpServletResponse.SC_BAD_REQUEST;
|
||||
}
|
||||
})
|
||||
.orElse(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
|
||||
pResponse.setStatus(httpResponseCode);
|
||||
}
|
||||
|
||||
@PostMapping("/signin")
|
||||
|
||||
Reference in New Issue
Block a user