Search in sources :

Example 1 with ForgotEmailDTO

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;
}
Also used : ForgotEmailDTO(com.nixmash.blog.jpa.dto.ForgotEmailDTO) CurrentUser(com.nixmash.blog.jpa.model.CurrentUser) User(com.nixmash.blog.jpa.model.User) UserToken(com.nixmash.blog.jpa.model.UserToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ForgotEmailDTO (com.nixmash.blog.jpa.dto.ForgotEmailDTO)1 CurrentUser (com.nixmash.blog.jpa.model.CurrentUser)1 User (com.nixmash.blog.jpa.model.User)1 UserToken (com.nixmash.blog.jpa.model.UserToken)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1