コード例 #1
0
  /**
   * After recover password
   *
   * @return
   */
  @Override
  public String recover() {
    logger.debug("recover");
    try {
      if (!ValidatorHelper.isRequired(this.token)) {
        WebHelper.addMessageFromBundle(
            keyRepository.getResourceBundle(),
            "message.token.invalid",
            null,
            FacesMessage.SEVERITY_ERROR);
        return null;
      }

      if (!ValidatorHelper.isSamePassword(this.newPassword, this.newPasswordVerifier)) {
        WebHelper.addMessageFromBundle(
            keyRepository.getResourceBundle(),
            "error.account.password.differents",
            null,
            FacesMessage.SEVERITY_ERROR);
        return null;
      }

      this.passwordRecoveryBO.resetPassword(this.token, this.newPassword);
      return Redirect.redirect("/login");
    } catch (Exception e) {
      logger.error("revery failed", e);
    }
    return null;
  }
コード例 #2
0
  @Override
  public String send() {
    logger.debug("send password recovery token");
    try {
      // data = email

      if (!ValidatorHelper.isEmail(this.email)) {
        WebHelper.addMessageFromBundle(
            keyRepository.getResourceBundle(),
            "message.email.error",
            null,
            FacesMessage.SEVERITY_FATAL);
        return null;
      }
      this.passwordRecoveryBO.generateAndSendUrl(this.email);

      WebHelper.addMessageFromBundle(
          keyRepository.getResourceBundle(),
          "message.send.email.token",
          null,
          FacesMessage.SEVERITY_INFO);
      return Redirect.redirect("/jsp/user/editPassword");
    } catch (ServiceException e) {
      WebHelper.addMessageFromBundle(
          keyRepository.getResourceBundle(),
          "message.recovery.internal.error",
          null,
          FacesMessage.SEVERITY_ERROR);
      logger.error("Send password recovery token failed", e);
    } catch (NotFoundException e) {
      WebHelper.addMessageFromBundle(
          keyRepository.getResourceBundle(),
          "message.account.not.found",
          null,
          FacesMessage.SEVERITY_ERROR);
      logger.error("Send password recovery token failed", e);
    } catch (Exception e) {
      WebHelper.addMessageFromBundle(
          keyRepository.getResourceBundle(),
          "message.recovery.internal.error",
          null,
          FacesMessage.SEVERITY_ERROR);
      logger.error("Send password recovery token failed", e);
    }
    return null;
  }
コード例 #3
0
  /*
   * (non-Javadoc)
   * @see fr.dorian.web.PasswordRecoveryBean#save()
   */
  @Override
  @Secured(Secure.ROLE_USER)
  public String save() {
    logger.debug("save");
    try {

      if (!ValidatorHelper.isRequired(this.data)) {
        WebHelper.addMessageFromBundle(
            keyRepository.getResourceBundle(),
            "message.token.invalid",
            null,
            FacesMessage.SEVERITY_ERROR);
        return null;
      }

      if (!ValidatorHelper.isSamePassword(this.newPassword, this.newPasswordVerifier)) {
        WebHelper.addMessageFromBundle(
            keyRepository.getResourceBundle(),
            "error.account.password.differents",
            null,
            FacesMessage.SEVERITY_ERROR);
        return null;
      }

      this.accountBO.changePassword(
          this.accountContext.getCurrentAccount().getId(), this.newPassword);
      WebHelper.addMessageFromBundle(
          keyRepository.getResourceBundle(), "message.save.ok", null, FacesMessage.SEVERITY_INFO);
      return Redirect.redirect("/jsp/user/account");
    } catch (ServiceException e) {
      e.printStackTrace();
    } catch (Exception e) {
      WebHelper.addMessageFromBundle(
          keyRepository.getResourceBundle(),
          "message.recovery.internal.error",
          null,
          FacesMessage.SEVERITY_ERROR);
      logger.error("Send password recovery token failed", e);
    }
    return null;
  }