Search in sources :

Example 26 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.

the class PasswordServiceImpl method getNewRestorationTokenForUser.

@Override
@Transactional(rollbackFor = Throwable.class)
public String getNewRestorationTokenForUser(String userUuid) throws UserNotFoundException {
    Preconditions.checkArgument(userUuid != null);
    assertUserExists(userUuid);
    try {
        String restorationToken = UUID.randomUUID().toString();
        int updateResult = passwordDao.setRestorationToken(userUuid, restorationToken);
        if (updateResult != 1) {
            throw new RuntimeException("createRestorationToken returned unexpected result = " + updateResult);
        }
        return restorationToken;
    } catch (Throwable t) {
        String msg = String.format("Failed to create restoration token for user '%s'", userUuid);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with UserServiceUnexpectedException

use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.

the class UsersServiceFacadeImpl method resetPassword.

@Transactional(rollbackFor = Throwable.class)
@Override
public void resetPassword(String email, String passwordResetToken, PasswordReset resetPasswordRequest) throws UserNotFoundException, FieldValidationException {
    try {
        String userUuid = assertPasswordResetOperationValid(email, passwordResetToken, resetPasswordRequest);
        passwordService.setUserPassword(userUuid, resetPasswordRequest.getPassword());
        // generate new token in order to invalidate current
        passwordService.getNewRestorationTokenForUser(userUuid);
        // If account requires activation, do it
        if (isAccountRequiresActivation(userUuid)) {
            activateAccount(userUuid);
        }
    } catch (Throwable e) {
        Throwables.throwIfInstanceOf(e, FieldValidationException.class);
        throw new UserServiceUnexpectedException("Failed to arrange password reset", e);
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)27 Transactional (org.springframework.transaction.annotation.Transactional)18 User (org.summerb.users.api.dto.User)11 FieldValidationException (org.summerb.validation.FieldValidationException)11 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)9 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 AuthToken (org.summerb.users.api.dto.AuthToken)3 AuthTokenNotFoundException (org.summerb.users.api.exceptions.AuthTokenNotFoundException)3 InvalidPasswordException (org.summerb.users.api.exceptions.InvalidPasswordException)2 DuplicateUserValidationError (org.summerb.users.api.validation.DuplicateUserValidationError)2 Password (org.summerb.users.impl.dom.Password)2 Date (java.util.Date)1 ValidationError (org.summerb.validation.ValidationError)1 FieldRequiredValidationError (org.summerb.validation.errors.FieldRequiredValidationError)1 UserStatus (org.summerb.webappboilerplate.security.dto.UserStatus)1 RegistrationAlreadyRequestedValidationError (org.summerb.webappboilerplate.security.ve.RegistrationAlreadyRequestedValidationError)1