use of won.owner.model.EmailVerificationToken in project webofneeds by researchstudio-sat.
the class RegistrationListener method onApplicationEvent.
@Override
public void onApplicationEvent(OnRegistrationCompleteEvent event) {
User user = event.getUser();
EmailVerificationToken emailVerificationToken = userService.createEmailVerificationToken(user);
emailSender.sendVerificationMessage(user, emailVerificationToken);
}
use of won.owner.model.EmailVerificationToken in project webofneeds by researchstudio-sat.
the class RestUserController method resendVerificationEmail.
@ResponseBody
@RequestMapping(value = "/resendVerificationEmail", method = RequestMethod.POST)
@Transactional(propagation = Propagation.SUPPORTS)
public ResponseEntity resendVerificationEmail(@RequestBody UsernamePojo usernamePojo) {
logger.debug("processing request to /resendVerificationEmail");
User user = userService.getByUsername(usernamePojo.getUsername());
if (user == null) {
return generateStatusResponse(RestStatusResponse.USER_NOT_FOUND);
}
if (user.isAnonymous()) {
return generateStatusResponse(RestStatusResponse.TOKEN_RESEND_FAILED_USER_ANONYMOUS);
}
if (user.isEmailVerified()) {
return generateStatusResponse(RestStatusResponse.TOKEN_RESEND_FAILED_ALREADY_VERIFIED);
}
EmailVerificationToken verificationToken = userService.getEmailVerificationToken(user);
if (verificationToken == null || verificationToken.isExpired()) {
verificationToken = userService.createEmailVerificationToken(user);
}
if (verificationToken == null) {
return generateStatusResponse(RestStatusResponse.TOKEN_CREATION_FAILED);
}
emailSender.sendVerificationMessage(user, verificationToken);
return generateStatusResponse(RestStatusResponse.TOKEN_RESEND_SUCCESS);
}
use of won.owner.model.EmailVerificationToken in project webofneeds by researchstudio-sat.
the class RestUserController method confirmRegistration.
@ResponseBody
@RequestMapping(value = "/confirmRegistration", method = RequestMethod.POST)
@Transactional(propagation = Propagation.SUPPORTS)
public ResponseEntity confirmRegistration(@RequestBody VerificationTokenPojo token) {
logger.debug("processing request to /confirmRegistration");
EmailVerificationToken verificationToken = userService.getEmailVerificationToken(token.getToken());
if (verificationToken == null) {
return generateStatusResponse(RestStatusResponse.TOKEN_NOT_FOUND);
}
if (verificationToken.getPurpose() != TokenPurpose.INITIAL_EMAIL_VERIFICATION) {
return generateStatusResponse(RestStatusResponse.TOKEN_PURPOSE_MISMATCH);
}
User user = verificationToken.getUser();
Calendar cal = Calendar.getInstance();
if ((verificationToken.getExpiryDate().getTime() - cal.getTime().getTime()) <= 0) {
return generateStatusResponse(RestStatusResponse.TOKEN_EXPIRED);
}
user.setEmailVerified(true);
userService.save(user);
return generateStatusResponse(RestStatusResponse.TOKEN_VERIFICATION_SUCCESS);
}
use of won.owner.model.EmailVerificationToken in project webofneeds by researchstudio-sat.
the class UserService method createEmailVerificationToken.
public EmailVerificationToken createEmailVerificationToken(User user, String verificationToken) {
EmailVerificationToken token = new EmailVerificationToken(user, verificationToken);
emailVerificationRepository.save(token);
return token;
}
Aggregations