1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.events;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.model.Group;
27  import com.liferay.portal.model.Layout;
28  import com.liferay.portal.model.LayoutTypePortlet;
29  import com.liferay.portal.model.ReverseAjax;
30  import com.liferay.portal.service.GroupLocalServiceUtil;
31  import com.liferay.portal.service.LayoutLocalServiceUtil;
32  import com.liferay.portal.struts.Action;
33  import com.liferay.portal.struts.ActionException;
34  import com.liferay.portal.util.LiveUsers;
35  import com.liferay.portal.util.PortalUtil;
36  import com.liferay.portal.util.PropsUtil;
37  import com.liferay.portal.util.WebKeys;
38  import com.liferay.portlet.messaging.util.MessagingUtil;
39  
40  import java.util.Iterator;
41  
42  import javax.servlet.http.HttpServletRequest;
43  import javax.servlet.http.HttpServletResponse;
44  import javax.servlet.http.HttpSession;
45  
46  import org.apache.commons.logging.Log;
47  import org.apache.commons.logging.LogFactory;
48  import org.apache.struts.Globals;
49  
50  /**
51   * <a href="LoginPostAction.java.html"><b><i>View Source</i></b></a>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   */
56  public class LoginPostAction extends Action {
57  
58      public void run(HttpServletRequest req, HttpServletResponse res)
59          throws ActionException {
60  
61          try {
62              if (_log.isDebugEnabled()) {
63                  _log.debug("Running " + req.getRemoteUser());
64              }
65  
66              HttpSession ses = req.getSession();
67  
68              long companyId = PortalUtil.getCompanyId(req);
69              long userId = PortalUtil.getUserId(req);
70  
71              if (GetterUtil.getBoolean(
72                      PropsUtil.get(PropsUtil.REVERSE_AJAX_ENABLED))) {
73  
74                  ses.setAttribute(WebKeys.REVERSE_AJAX, new ReverseAjax());
75              }
76  
77              MessagingUtil.createXMPPConnection(ses, userId);
78  
79              LiveUsers.signIn(req);
80  
81              if (!GetterUtil.getBoolean(PropsUtil.get(PropsUtil.
82                      LAYOUT_REMEMBER_SESSION_WINDOW_STATE_MAXIMIZED))) {
83  
84                  Group group = GroupLocalServiceUtil.getUserGroup(
85                      companyId, userId);
86  
87                  Iterator itr = LayoutLocalServiceUtil.getLayouts(
88                      group.getGroupId(), true).iterator();
89  
90                  while (itr.hasNext()) {
91                      Layout layout = (Layout)itr.next();
92  
93                      LayoutTypePortlet layoutType =
94                          (LayoutTypePortlet)layout.getLayoutType();
95  
96                      if (layoutType.hasStateMax()) {
97  
98                          // Set the window state to normal for the maximized
99                          // portlet
100 
101                         layoutType.resetStates();
102 
103                         // Set the portlet mode to view because other modes may
104                         // require a maximized window state
105 
106                         layoutType.resetModes();
107 
108                         LayoutLocalServiceUtil.updateLayout(
109                             layout.getGroupId(), layout.isPrivateLayout(),
110                             layout.getLayoutId(), layout.getTypeSettings());
111                     }
112                 }
113             }
114 
115             // Reset the locale
116 
117             ses.removeAttribute(Globals.LOCALE_KEY);
118         }
119         catch (Exception e) {
120             throw new ActionException(e);
121         }
122     }
123 
124     private static Log _log = LogFactory.getLog(LoginPostAction.class);
125 
126 }