Search in sources :

Example 1 with TokenStoreEntity

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;
}
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 TokenStoreEntity

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;
}
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 TokenStoreEntity

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);
}
Also used : TokenStoreEntity(org.codenergic.theskeleton.tokenstore.TokenStoreEntity)

Aggregations

TokenStoreEntity (org.codenergic.theskeleton.tokenstore.TokenStoreEntity)3 RegistrationException (org.codenergic.theskeleton.registration.RegistrationException)2 UserEntity (org.codenergic.theskeleton.user.UserEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2