Search in sources :

Example 1 with TokenStoreRestData

use of org.codenergic.theskeleton.tokenstore.TokenStoreRestData in project theskeleton by codenergic.

the class RegistrationServiceImpl method changePassword.

@Override
@Transactional
public void changePassword(String activationToken, String password) {
    try {
        TokenStoreRestData token = tokenStoreService.findAndVerifyToken(activationToken);
        if (token.isExpired()) {
            throw new RegistrationException("Key is Expired");
        }
        UserEntity user = (UserEntity) token.getUser();
        user.setPassword(passwordEncoder.encode(password));
    } catch (InvalidSignatureException e) {
        throw new RegistrationException("Invalid Token");
    }
}
Also used : InvalidSignatureException(org.springframework.security.jwt.crypto.sign.InvalidSignatureException) TokenStoreRestData(org.codenergic.theskeleton.tokenstore.TokenStoreRestData) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TokenStoreRestData

use of org.codenergic.theskeleton.tokenstore.TokenStoreRestData in project theskeleton by codenergic.

the class RegistrationServiceImpl method activateUser.

@Override
@Transactional
public void activateUser(String activationToken) {
    try {
        TokenStoreRestData token = tokenStoreService.findAndVerifyToken(activationToken);
        UserEntity user = (UserEntity) token.getUser();
        if (user.isEnabled()) {
            throw new RegistrationException("Your Account is already activated");
        }
        user.setEnabled(true);
    } catch (InvalidSignatureException e) {
        throw new RegistrationException("Invalid Activation Key");
    }
}
Also used : InvalidSignatureException(org.springframework.security.jwt.crypto.sign.InvalidSignatureException) TokenStoreRestData(org.codenergic.theskeleton.tokenstore.TokenStoreRestData) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with TokenStoreRestData

use of org.codenergic.theskeleton.tokenstore.TokenStoreRestData in project theskeleton by codenergic.

the class ChangePasswordController method updateView.

@GetMapping(path = "/update")
public String updateView(@RequestParam(name = "rt") String resetToken, UpdatePasswordForm updatePasswordForm) {
    try {
        TokenStoreRestData token = tokenStoreService.findAndVerifyToken(resetToken);
        updatePasswordForm.setToken(token.getSignedToken());
        return CHANGEPASS_UPDATE;
    } catch (InvalidSignatureException e) {
        return "redirect:/changepass";
    }
}
Also used : InvalidSignatureException(org.springframework.security.jwt.crypto.sign.InvalidSignatureException) TokenStoreRestData(org.codenergic.theskeleton.tokenstore.TokenStoreRestData) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

TokenStoreRestData (org.codenergic.theskeleton.tokenstore.TokenStoreRestData)3 InvalidSignatureException (org.springframework.security.jwt.crypto.sign.InvalidSignatureException)3 UserEntity (org.codenergic.theskeleton.user.UserEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)1