Search in sources :

Example 1 with EmailValidator

use of org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator in project jprime by bgjug.

the class CfpController method validateEmail.

private String validateEmail(BindingResult bindingResult, Submission submission, Model model, String email, String role) {
    EmailValidator emailValidator = new EmailValidator();
    if (!StringUtils.isEmpty(email) && emailValidator.isValid(email, null)) {
        // Email is valid
        return null;
    }
    bindingResult.addError(new FieldError("submission", role + ".email", "Invalid Email!"));
    return goToCFP(submission, model);
}
Also used : EmailValidator(org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator) FieldError(org.springframework.validation.FieldError)

Example 2 with EmailValidator

use of org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator in project jprime by bgjug.

the class UserController method resetPassword.

@RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
public String resetPassword(@RequestParam(value = "email") String email, Model model, final RedirectAttributes redirectAttrs) {
    EmailValidator mailValidator = new EmailValidator();
    if (!mailValidator.isValid(email, null)) {
        model.addAttribute("error_msg", "Please, enter a valid mail address");
        return RESET_PASSWORD_JSP;
    }
    User user = getUserRepository().findUserByEmail(email);
    if (user != null) {
        String tokenId = resetPassService.createNewToken(user);
        try {
            String mailContent = buildResetMailContent(user, tokenId, "/resetPasswordMail.html");
            String mailTitle = "Reset your JPrime password";
            mailService.sendEmail(email, mailTitle, mailContent);
        } catch (MessagingException | IOException | URISyntaxException e) {
            logger.error("Error while sending ResetPassword Mail to  " + user, e);
        }
    }
    redirectAttrs.addFlashAttribute("sent_to_email", email);
    return "redirect:/resetPassword";
}
Also used : EmailValidator(org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator) User(site.model.User) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EmailValidator (org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 MessagingException (javax.mail.MessagingException)1 FieldError (org.springframework.validation.FieldError)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 User (site.model.User)1