use of com.nixmash.blog.jpa.dto.ForgotEmailDTO in project nixmash-blog by mintster.
the class UserPasswordController method sendForgotEmail.
@RequestMapping(value = "/users/forgotpassword", method = POST)
public String sendForgotEmail(@Valid ForgotEmailDTO forgotEmailDTO, BindingResult result, Model model) {
if (result.hasErrors()) {
return USER_FORGOTPASSWORD_VIEW;
} else {
Optional<User> user = userService.getByEmail(forgotEmailDTO.getEmail());
if (!user.isPresent()) {
result.reject("global.error.email.does.not.exist");
} else {
model.addAttribute(FLASH_MESSAGE_KEY_FEEDBACK, webUI.getMessage(FEEDBACK_PASSWORD_EMAIL_SENT));
model.addAttribute("forgotEmailDTO", new ForgotEmailDTO());
UserToken userToken = userService.createUserToken(user.get());
fmMailService.sendResetPasswordMail(user.get(), userToken.getToken());
}
}
return USER_FORGOTPASSWORD_VIEW;
}
Aggregations