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;
}
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;
}
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");
}
}
Aggregations