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