Ejemplo n.º 1
0
  @Override
  public void changePassword(ChangePasswordData cpd) {
    notNull(cpd, Messages.VALIDATION_ACCOUNT_DATA_EMPTY);
    hasLength(cpd.getCurrentPassword(), Messages.VALIDATION_CURRENT_PASSWOD_EMPTY);
    hasLength(cpd.getPassword(), Messages.VALIDATION_PASSWOD_EMPTY);
    hasLength(cpd.getConfirmPassword(), Messages.VALIDATION_CONFIRM_PASSWORD_EMPTY);

    User user = userDao.findById(cpd.getUserId());

    validationService.validatePassword(user.getName(), cpd.getPassword(), cpd.getConfirmPassword());

    user.setPassword(cryptoService.crypt(cpd.getPassword()));
    // TODO should store the date of password change in another column?
    user.setLastUpdatedOn(new Date());
  }
Ejemplo n.º 2
0
  @Override
  @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
  public void resetPassword(ResetPasswordData rpd) {
    hasLength(rpd.getPassword(), Messages.VALIDATION_PASSWOD_EMPTY);
    hasLength(rpd.getConfirmPassword(), Messages.VALIDATION_CONFIRM_PASSWORD_EMPTY);
    hasLength(rpd.getResetPasswordToken(), Messages.VALIDATION_INVALID_RESET_PASSWORD_TOKEN);

    User user = userDao.findByResetPasswordToken(rpd.getResetPasswordToken());
    if (user != null) {
      validationService.validatePassword(
          user.getName(), rpd.getPassword(), rpd.getConfirmPassword());
      user.setPassword(cryptoService.crypt(rpd.getPassword()));
      user.setResetPasswordToken(null);
    } else {
      throw new IllegalArgumentException(Messages.VALIDATION_INVALID_RESET_PASSWORD_TOKEN);
    }
  }
Ejemplo n.º 3
0
  private void validate(RegistrationData rd) {
    notNull(rd, Messages.VALIDATION_REG_FORM_EMPTY);
    hasLength(rd.getName(), Messages.VALIDATION_NAME_EMPTY);
    hasLength(rd.getEmail(), Messages.VALIDATION_EMAIL_EMPTY);
    hasLength(rd.getPassword(), Messages.VALIDATION_PASSWOD_EMPTY);
    hasLength(rd.getConfirmPassword(), Messages.VALIDATION_CONFIRM_PASSWORD_EMPTY);

    if (rd.getName().length() < 10) {
      throw new IllegalArgumentException(Messages.VALIDATION_NAME_TOO_SHORT);
    }

    validationService.validateEmail(rd.getEmail());

    validationService.validatePassword(rd.getName(), rd.getPassword(), rd.getConfirmPassword());

    if (userDao.findByEmail(rd.getEmail()) != null) {
      throw new IllegalArgumentException(Messages.VALIDATION_EMAIL_ALREADY_REGISTERED);
    }
  }