use of py.org.fundacionparaguaya.pspserver.security.entities.PasswordResetTokenEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class PasswordResetTokenServiceImpl method validatePasswordResetToken.
@Override
public void validatePasswordResetToken(String token, Long userId, String password, String repeatPassword) {
checkArgument(userId > 0, i18n.translate("argument.nonNegative", userId));
UserEntity userEntity = userRepository.findOne(userId);
if (userEntity == null) {
throw new UnknownResourceException(i18n.translate("user.notExist", userId));
}
PasswordResetTokenEntity passwordResetTokenEntity = passwordTokenRepository.findByToken(token);
if (passwordResetTokenEntity == null || passwordResetTokenEntity.getUser().getId().longValue() != userId.longValue()) {
throw new CustomParameterizedException(i18n.translate("email.invalidToken", token));
}
Calendar cal = Calendar.getInstance();
if ((passwordResetTokenEntity.getExpiryDate().getTime() - cal.getTime().getTime()) <= 0) {
throw new CustomParameterizedException(i18n.translate("email.expiredToken", token));
}
if (!password.equals(repeatPassword)) {
throw new CustomParameterizedException("Password does not match the confirm password");
}
userEntity.setPass(encryptPassword(repeatPassword));
userRepository.save(userEntity);
}
use of py.org.fundacionparaguaya.pspserver.security.entities.PasswordResetTokenEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class PasswordResetTokenServiceImpl method createPasswordResetTokenForUser.
@Override
public void createPasswordResetTokenForUser(UserEntity user, String token) {
PasswordResetTokenEntity myToken = new PasswordResetTokenEntity(token, user);
LocalDateTime expirationLocalDate = LocalDateTime.now().plusMinutes(PasswordResetTokenEntity.getExpiration());
Instant instant = expirationLocalDate.toInstant(ZoneOffset.UTC);
Date expirationDate = Date.from(instant);
myToken.setExpiryDate(expirationDate);
passwordTokenRepository.save(myToken);
}
Aggregations