Search in sources :

Example 1 with EmailVerificationToken

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);
}
Also used : User(won.owner.model.User) EmailVerificationToken(won.owner.model.EmailVerificationToken)

Example 2 with 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);
}
Also used : User(won.owner.model.User) EmailVerificationToken(won.owner.model.EmailVerificationToken) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EmailVerificationToken

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);
}
Also used : User(won.owner.model.User) EmailVerificationToken(won.owner.model.EmailVerificationToken) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with EmailVerificationToken

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;
}
Also used : EmailVerificationToken(won.owner.model.EmailVerificationToken)

Aggregations

EmailVerificationToken (won.owner.model.EmailVerificationToken)4 User (won.owner.model.User)3 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2