Package com.dotmarketing.cms.forgotpassword.struts

Examples of com.dotmarketing.cms.forgotpassword.struts.ForgotPasswordForm


   * link gotten in your email that case it sends you to the reset password page
   */
  public ActionForward unspecified(ActionMapping mapping, ActionForm lf, HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    ActionForward af = (mapping.findForward("forgotPasswordPage"));
    ForgotPasswordForm form = (ForgotPasswordForm) lf;
   
    if (UtilMethods.isSet(form.getAccKey()) && Config.getBooleanProperty("USE_RESET_PASSWORD_EMAIL")) {     
      request.setAttribute("email", form.getEmail());
      af = (mapping.findForward("resetPasswordPage"));
    }
   
    if (Config.getBooleanProperty("USE_CHALLENGE_QUESTION"))
    {
         af = new ActionForward(SecurityUtils.stripReferer(
                     request, mapping.findForward("challengeQuestionPage").getPath() + "?emailAddress=" + form.getEmail()));
      }
   
    return af;
  }
View Full Code Here


  public ActionForward forgotPassword(ActionMapping mapping, ActionForm lf, HttpServletRequest request,
      HttpServletResponse response) throws Exception {
   
    //setting some variables
    ActionForward af = (mapping.findForward("forgotPasswordPage"));
    ForgotPasswordForm form = (ForgotPasswordForm) lf;
    request.setAttribute("email", form.getEmail());

    String referrer = null;
    if (request.getAttribute("referrer") != null && !request.getAttribute("referrer").toString().equalsIgnoreCase(""))
    {
      referrer = (String)request.getAttribute("referrer");
    }
    else if (request.getParameter("referrer") != null && !request.getParameter("referrer").toString().equalsIgnoreCase(""))
    {
      referrer = SecurityUtils.stripReferer(request, (String)request.getParameter("referrer"));
    }
   
    try {
      //Validating the input
      if(!APILocator.getUserAPI().userExistsWithEmail(form.getEmail())) {
        ActionMessages aes = new ActionErrors();
        aes.add(Globals.ERROR_KEY, new ActionMessage("error.user.email.doesnt.exists"));
        saveErrors(request, aes);
        return af;
      }
    } catch (DotDataException e) {
      ActionMessages aes = new ActionErrors();
      aes.add(Globals.ERROR_KEY, new ActionMessage("error.user.email.doesnt.exists"));
      saveErrors(request, aes);
      return af;
    } catch (NoSuchUserException e) {
      ActionMessages aes = new ActionErrors();
      aes.add(Globals.ERROR_KEY, new ActionMessage("error.user.email.doesnt.exists"));
      saveErrors(request, aes);
      return af;
    }
   
    //If the user doesn't exists
    User user = APILocator.getUserAPI().loadByUserByEmail(form.getEmail(), APILocator.getUserAPI().getSystemUser(), false);
    if(user.isNew()){
      ActionErrors aes = new ActionErrors();
      aes.add(Globals.ERROR_KEY, new ActionMessage("error.user.email.doesnt.exists"));
      saveMessages(request.getSession(), aes);
     
      if(UtilMethods.isSet(referrer)) {
            af = new ActionForward(SecurityUtils.stripReferer(request, referrer));
            af.setRedirect(true);
            return af;
      } else
        return af;
     
    }

    //If the account is not active
    if(!user.isActive()){
     
      ActionMessages aes = new ActionErrors();
      aes.add(Globals.ERROR_KEY, new ActionMessage("error.user.is.not.active"));
      saveErrors(request, aes);
     
          af = mapping.findForward("resendActivationPage");
          return af;
     
    }
   
   
    if (Config.getBooleanProperty("USE_CHALLENGE_QUESTION")) {
   
      request.setAttribute("email", form.getEmail());
      form.setAccKey(PublicEncryptionFactory.encryptString(user.getUserId()));
      return mapping.findForward("challengeQuestionPage");
   
    } else if (Config.getBooleanProperty("USE_RESET_PASSWORD_EMAIL")) {     
   
      request.setAttribute("email", form.getEmail());
      return sendResetPassword(mapping, lf, request, response);

    } else {
     
      //if we have some errors
View Full Code Here

   * This method verifies that the correct challenge question has been answered by the user and then
   * sends the random generated password through email
   */
    public ActionForward verifyChallengeQuestion(ActionMapping mapping, ActionForm lf, HttpServletRequest request, HttpServletResponse response) throws Exception {
     
      ForgotPasswordForm fpf = (ForgotPasswordForm) lf;
    String acckeyCrypted = fpf.getAccKey();
    String acckey = acckeyCrypted;
   
    try {
      acckey = PublicEncryptionFactory.decryptString(acckeyCrypted);
    } catch (Exception e) {
    }
   
    String referrer = null;
    if (request.getAttribute("referrer") != null && !request.getAttribute("referrer").toString().equalsIgnoreCase("")) {
      referrer = (String)request.getAttribute("referrer");
    } else if (request.getParameter("referrer") != null && !request.getParameter("referrer").toString().equalsIgnoreCase("")) {
      referrer = SecurityUtils.stripReferer(request, (String)request.getParameter("referrer"));
    }
   
        try {
         
          User user = APILocator.getUserAPI().loadByUserByEmail(acckey, APILocator.getUserAPI().getSystemUser(), false);
          Company company = PublicCompanyFactory.getDefaultCompany();
         
        request.setAttribute("email", user.getEmailAddress());
         
        String email = UtilMethods.isSet(request.getParameter("email"))?request.getParameter("email"):user.getEmailAddress();
          UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(user,APILocator.getUserAPI().getSystemUser(), false);
          String challengeQuestionAnswer = request.getParameter("challengeQuestionAnswer");
         
          if (userProxy.getChallengeQuestionAnswer().equalsIgnoreCase(challengeQuestionAnswer)) {
       
        String pass = PublicEncryptionFactory.getRandomPassword();
        user.setPassword(PublicEncryptionFactory.digestString(pass));
        APILocator.getUserAPI().save(user,APILocator.getUserAPI().getSystemUser(),false);
        Host host = hostWebAPI.getCurrentHost(request);
        try {
          HashMap<String, Object> parameters = new HashMap<String, Object> ();
          parameters.put("subject", "Your " + host.getHostname() + " Password");
          parameters.put("password", pass);
          parameters.put("emailTemplate", Config.getStringProperty("CHALLENGE_QUESTION_EMAIL_TEMPLATE"));
          parameters.put("to", email);
          parameters.put("from", company.getEmailAddress());
         
          EmailFactory.sendParameterizedEmail(parameters, null, host, user);
         
          ActionMessages msg = new ActionMessages();
                msg.add(Globals.MESSAGE_KEY, new ActionMessage("message.challenge_question.answer_successful", email));
                saveMessages(request.getSession(), msg);
                if(UtilMethods.isSet(referrer)) {
                return (new ActionForward(SecurityUtils.stripReferer(request, referrer + "?" + request.getQueryString())));
                } else {
                  return mapping.findForward("passwordChangeConfirmationPage");
                }
        } catch (Exception e) {
              ActionMessages msg = new ActionMessages();
                msg.add(Globals.ERROR_KEY, new ActionMessage("error.send_email"));
                request.setAttribute(Globals.ERROR_KEY, msg);
                return mapping.findForward("challengeQuestionPage");
        }
          } else {
            ActionMessages msg = new ActionMessages();
              msg.add(Globals.ERROR_KEY, new ActionMessage("message.challenge_question.answer_failure"));
              request.setAttribute(Globals.ERROR_KEY, msg);
              fpf.setAccKey(PublicEncryptionFactory.encryptString(user.getUserId()));
              fpf.setEmail(user.getEmailAddress());
             
              return mapping.findForward("challengeQuestionPage");
          }
    } catch (Exception e) {
      Logger.debug(this, "Failed - Redirecting to: loginPage");
View Full Code Here

   */
  public ActionForward resetPassword(ActionMapping mapping, ActionForm lf,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    ForgotPasswordForm form = (ForgotPasswordForm)lf;
   
    String acckeyCrypted = form.getAccKey();
      Logger.debug(AccountActivationAction.class, "acckeyCrypted="+acckeyCrypted);
    String acckey = PublicEncryptionFactory.decryptString(acckeyCrypted);
      Logger.debug(AccountActivationAction.class, "acckey="+acckey);
    StringTokenizer strTok = new StringTokenizer(acckey, "##");

    String userId = strTok.nextToken();
    String linkExpirationDateStr = strTok.nextToken();

    Date linkExpirationDate = UtilMethods.jdbcToDate(linkExpirationDateStr);
    User user = APILocator.getUserAPI().loadUserById(userId,APILocator.getUserAPI().getSystemUser(),false);

    ActionMessages am = new ActionMessages();

    if (!user.isNew()) {
   
      // the user is active
      // validating reset password email link

      if (linkExpirationDate.after(new Date())) {

        // updating user password
        if (!Validator.validate(request, lf, mapping))
          return mapping.findForward("resetPasswordPage");

        user.setPassword(PublicEncryptionFactory.digestString(form.getNewPassword()));
        user.setPasswordEncrypted(true);

        APILocator.getUserAPI().save(user,APILocator.getUserAPI().getSystemUser(),false);

        Company comp = com.dotmarketing.cms.factories.PublicCompanyFactory.getDefaultCompany();
        if (comp.getAuthType().equals(Company.AUTH_TYPE_EA)) {
          LoginFactory.doLogin(user.getEmailAddress(), form.getNewPassword(), false, request, response);
        } else {
          LoginFactory.doLogin(user.getUserId(), form.getNewPassword(), false, request, response);
        }

        am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.forgot.password.password.updated"));
        saveMessages(request, am);
        return mapping.findForward("passwordChangeConfirmationPage");
View Full Code Here

TOP

Related Classes of com.dotmarketing.cms.forgotpassword.struts.ForgotPasswordForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.