1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.myaccount.action;
16  
17  import com.liferay.portal.UserPasswordException;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.model.User;
21  import com.liferay.portal.util.PortalUtil;
22  import com.liferay.portlet.RenderRequestImpl;
23  import com.liferay.util.servlet.DynamicServletRequest;
24  
25  import javax.portlet.ActionRequest;
26  import javax.portlet.ActionResponse;
27  import javax.portlet.PortletConfig;
28  import javax.portlet.RenderRequest;
29  import javax.portlet.RenderResponse;
30  
31  import org.apache.struts.action.ActionForm;
32  import org.apache.struts.action.ActionForward;
33  import org.apache.struts.action.ActionMapping;
34  
35  /**
36   * <a href="EditUserAction.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
40  public class EditUserAction
41      extends com.liferay.portlet.enterpriseadmin.action.EditUserAction {
42  
43      public void processAction(
44              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
45              ActionRequest actionRequest, ActionResponse actionResponse)
46          throws Exception {
47  
48          if (redirectToLogin(actionRequest, actionResponse)) {
49              return;
50          }
51  
52          super.processAction(
53              mapping, form, portletConfig, actionRequest, actionResponse);
54      }
55  
56      public ActionForward render(
57              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
58              RenderRequest renderRequest, RenderResponse renderResponse)
59          throws Exception {
60  
61          User user = PortalUtil.getUser(renderRequest);
62  
63          RenderRequestImpl renderRequestImpl = (RenderRequestImpl)renderRequest;
64  
65          DynamicServletRequest dynamicRequest =
66              (DynamicServletRequest)renderRequestImpl.getHttpServletRequest();
67  
68          dynamicRequest.setParameter(
69              "p_u_i_d", String.valueOf(user.getUserId()));
70  
71          return super.render(
72              mapping, form, portletConfig, renderRequest, renderResponse);
73      }
74  
75      protected Object[] updateUser(ActionRequest actionRequest)
76          throws Exception {
77  
78          String newPassword = ParamUtil.getString(actionRequest, "password1");
79  
80          if (Validator.isNotNull(newPassword)) {
81              String requestPassword = ParamUtil.getString(
82                  actionRequest, "password0");
83  
84              String sessionPassword = PortalUtil.getUserPassword(actionRequest);
85  
86              if (!requestPassword.equals(sessionPassword)) {
87                  throw new UserPasswordException(
88                      UserPasswordException.PASSWORD_INVALID);
89              }
90          }
91  
92          return super.updateUser(actionRequest);
93      }
94  
95  }