use of org.codenergic.theskeleton.tokenstore.TokenStoreEntity 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.tokenstore.TokenStoreEntity 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.tokenstore.TokenStoreEntity in project theskeleton by codenergic.
the class TokenStoreServiceImpl method sendTokenNotification.
@Override
public TokenStoreEntity sendTokenNotification(TokenStoreType type, UserEntity user) {
String token = RandomStringUtils.randomAlphabetic(24);
TokenStoreEntity tokenStoreEntity = new TokenStoreEntity().setToken(token).setUser(user).setType(type).setExpiryDate(DateTime.now().plusDays(15).toDate());
sendEmail(tokenStoreEntity, user);
return tokenStoreRepository.save(tokenStoreEntity);
}
Aggregations