1 package com.dotmarketing.cms.login.action; 2 3 import javax.servlet.http.Cookie ; 4 import javax.servlet.http.HttpServletRequest ; 5 import javax.servlet.http.HttpServletResponse ; 6 7 import org.apache.commons.logging.LogFactory; 8 import org.apache.struts.Globals; 9 import org.apache.struts.action.ActionErrors; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionForward; 12 import org.apache.struts.action.ActionMapping; 13 import org.apache.struts.action.ActionMessage; 14 import org.apache.struts.action.ActionMessages; 15 import org.apache.struts.actions.DispatchAction; 16 17 import com.dotmarketing.beans.UserProxy; 18 import com.dotmarketing.cms.login.factories.LoginFactory; 19 import com.dotmarketing.cms.login.struts.LoginForm; 20 import com.dotmarketing.factories.UserProxyFactory; 21 import com.dotmarketing.util.UtilMethods; 22 import com.dotmarketing.util.WebKeys; 23 import com.liferay.portal.model.User; 24 25 28 public class LoginAction extends DispatchAction { 29 public ActionForward unspecified(ActionMapping mapping, ActionForm lf, HttpServletRequest request, 30 HttpServletResponse response) throws Exception { 31 LogFactory.getLog(this.getClass()).info("Locale: " + request.getSession().getAttribute(Globals.LOCALE_KEY)); 32 33 ActionForward af = (mapping.findForward("loginPage")); 34 35 return af; 36 } 37 38 public ActionForward login(ActionMapping mapping, ActionForm lf, HttpServletRequest request, 39 HttpServletResponse response) throws Exception { 40 LoginForm form = (LoginForm) lf; 41 42 if (LoginFactory.doLogin(form, request, response)) { 43 44 User u = (User) request.getSession().getAttribute(WebKeys.CMS_USER); 45 UserProxy userproxy = UserProxyFactory.getUserProxy(u); 46 if (UtilMethods.isSet(userproxy.getLongLivedCookie())) { 47 Cookie cookie = UtilMethods.getCookie(request.getCookies(), WebKeys.LONG_LIVED_DOTCMS_ID_COOKIE); 49 if (cookie != null) { 50 cookie.setMaxAge(-1); 51 } 52 response.addCookie(cookie); 53 } 54 else { 55 String _dotCMSID = UtilMethods.getCookieValue(request.getCookies(), WebKeys.LONG_LIVED_DOTCMS_ID_COOKIE); 56 if (UtilMethods.isSet(_dotCMSID)) { 57 userproxy.setLongLivedCookie(_dotCMSID); 58 } 59 } 60 61 if (request.getSession().getAttribute(WebKeys.REDIRECT_AFTER_LOGIN) != null) { 62 String redir = (String ) request.getSession().getAttribute(WebKeys.REDIRECT_AFTER_LOGIN); 63 request.getSession().removeAttribute(WebKeys.REDIRECT_AFTER_LOGIN); 64 LogFactory.getLog(this.getClass()).info("redirecting after account creation: " + redir); 65 ActionForward af = new ActionForward(redir); 66 af.setRedirect(true); 67 return af; 68 } 69 70 ActionMessages msg = new ActionMessages(); 71 msg.add(Globals.MESSAGE_KEY, new ActionMessage("message.Login.Successful")); 72 request.getSession().setAttribute(Globals.MESSAGE_KEY, msg); 73 74 ActionForward af = new ActionForward("/"); 75 af.setRedirect(true); 76 return af; 77 } 78 ActionErrors errors = new ActionErrors(); 79 errors.add(Globals.ERROR_KEY, new ActionMessage("error.badLogin")); 80 saveErrors(request, errors); 81 return mapping.findForward("loginPage"); 82 83 } 84 85 } | Popular Tags |