Search in sources :

Example 1 with RegistrationException

use of org.codenergic.theskeleton.registration.RegistrationException in project theskeleton by codenergic.

the class RegistrationServiceImpl method activateUser.

@Override
@Transactional
public boolean activateUser(String activationToken) {
    TokenStoreEntity tokenStoreEntity = tokenStoreRepository.findByTokenAndType(activationToken, TokenStoreType.USER_ACTIVATION);
    if (tokenStoreEntity == null)
        throw new RegistrationException("Invalid Activation Key");
    if (tokenStoreEntity.isTokenExpired())
        throw new RegistrationException("Activation Key is Expired");
    if (Activeable.Status.INACTIVE.getStatus() == tokenStoreEntity.getStatus())
        throw new RegistrationException("Your Account is already activated");
    UserEntity user = tokenStoreEntity.getUser();
    user.setEnabled(true);
    tokenStoreEntity.setStatus(Activeable.Status.INACTIVE.getStatus());
    return true;
}
Also used : RegistrationException(org.codenergic.theskeleton.registration.RegistrationException) TokenStoreEntity(org.codenergic.theskeleton.tokenstore.TokenStoreEntity) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RegistrationException

use of org.codenergic.theskeleton.registration.RegistrationException in project theskeleton by codenergic.

the class RegistrationServiceImpl method changePassword.

@Override
@Transactional
public boolean changePassword(String activationToken, String password) {
    TokenStoreEntity tokenStoreEntity = tokenStoreRepository.findByTokenAndType(activationToken, TokenStoreType.CHANGE_PASSWORD);
    if (tokenStoreEntity == null)
        throw new RegistrationException("Invalid Activation Key");
    if (tokenStoreEntity.isTokenExpired())
        throw new RegistrationException("Activation Key is Expired");
    UserEntity user = tokenStoreEntity.getUser();
    user.setPassword(passwordEncoder.encode(password));
    tokenStoreEntity.setStatus(Activeable.Status.INACTIVE.getStatus());
    return true;
}
Also used : RegistrationException(org.codenergic.theskeleton.registration.RegistrationException) TokenStoreEntity(org.codenergic.theskeleton.tokenstore.TokenStoreEntity) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RegistrationException

use of org.codenergic.theskeleton.registration.RegistrationException in project theskeleton by codenergic.

the class TokenStoreServiceImpl method sendEmail.

private void sendEmail(String token, TokenStoreType type, String email) {
    Map<String, Object> params = new HashMap<>();
    String subject;
    String template;
    if (TokenStoreType.USER_ACTIVATION.equals(type)) {
        params.put("activationUrl", emailBaseUrl + "/registration/activate?at=" + token);
        subject = "Registration Confirmation";
        template = "email/registration.html";
    } else {
        params.put("changepassUrl", emailBaseUrl + "/changepass/update?rt=" + token);
        subject = "Reset Password Confirmation";
        template = "email/changepass.html";
    }
    try {
        emailService.sendEmail(null, new InternetAddress(email), subject, params, template);
    } catch (AddressException e) {
        throw new RegistrationException("Unable to send activation link");
    }
}
Also used : RegistrationException(org.codenergic.theskeleton.registration.RegistrationException) InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) AddressException(javax.mail.internet.AddressException)

Aggregations

RegistrationException (org.codenergic.theskeleton.registration.RegistrationException)3 TokenStoreEntity (org.codenergic.theskeleton.tokenstore.TokenStoreEntity)2 UserEntity (org.codenergic.theskeleton.user.UserEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashMap (java.util.HashMap)1 AddressException (javax.mail.internet.AddressException)1 InternetAddress (javax.mail.internet.InternetAddress)1