1 package com.dotmarketing.cms.forgotpassword.action; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 import org.apache.struts.Globals; 6 import org.apache.struts.action.ActionErrors; 7 import org.apache.struts.action.ActionForm; 8 import org.apache.struts.action.ActionForward; 9 import org.apache.struts.action.ActionMapping; 10 import org.apache.struts.action.ActionMessage; 11 import org.apache.struts.actions.DispatchAction; 12 import com.dotmarketing.beans.Host; 13 import com.dotmarketing.cms.factories.PublicEncryptionFactory; 14 import com.dotmarketing.cms.factories.PublicUserFactory; 15 import com.dotmarketing.cms.forgotpassword.struts.ForgotPasswordForm; 16 import com.dotmarketing.factories.EmailFactory; 17 import com.dotmarketing.factories.HostFactory; 18 import com.liferay.portal.model.User; 19 20 21 28 public class ForgotPasswordAction extends DispatchAction { 29 public ActionForward unspecified(ActionMapping mapping, ActionForm lf, HttpServletRequest request, 30 HttpServletResponse response) throws Exception { 31 ActionForward af = (mapping.findForward("forgotPasswordPage")); 32 33 return af; 34 } 35 36 public ActionForward forgotPassword(ActionMapping mapping, ActionForm lf, HttpServletRequest request, 37 HttpServletResponse response) throws Exception { 38 ForgotPasswordForm form = (ForgotPasswordForm) lf; 39 40 ActionErrors aes= form.validate(mapping, request); 42 43 if(aes != null && aes.size() > 0){ 44 saveMessages(request, aes); 45 return mapping.getInputForward(); 46 } 47 User user = PublicUserFactory.getUserByEmail(form.getEmail()); 48 if(user.isNew()){ 49 aes= new ActionErrors(); 50 aes.add(Globals.ERROR_KEY, new ActionMessage("error.userDoesNotExist")); 51 saveMessages(request, aes); 52 return mapping.getInputForward(); 53 } 54 String pass = PublicEncryptionFactory.getRandomPassword(); 55 user.setPassword(PublicEncryptionFactory.digestString(pass)); 56 PublicUserFactory.save(user); 57 Host host = HostFactory.getCurrentHost(request); 58 EmailFactory.sendForgotPassword(user, pass, host.getInode()); 59 60 61 ActionForward af = (mapping.findForward("passwordResetPage")); 62 return af; 63 } 64 } 65 | Popular Tags |