Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change password from Custom portlet in liferay

    • 0
    • 5
    • 4
    • 3
    • 0
    • 0
    • 0
    • 0
    • 3.74k
    Comment on it

    Hello

    Below code will help you to implement change password from custom portlet.

    Please follow below steps :

    step 1 : create Action URL

    <portlet:actionURL name="updatePassword" var="updatePassword"/>
    

    step 2 : Write below code in JSP page

    <aui:form method="post" action="<%=updatePassword%>" name="updatepassword" id="updatepassword">    
            <aui:input label="" name="current" type="text"></aui:input>
            <aui:input label="" name="password1" type="text"></aui:input>
            <aui:input label="" name="password2" type="text"></aui:input>
            <aui:button type="submit" label="" value="Save"></aui:button>
            </aui:form> 
    

    step 3 : Write below Action Class

    public void updatePassword(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException
            {
                ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
                UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
                String current =uploadRequest.getParameter(actionResponse.getNamespace()+"current");
                String password1 =uploadRequest.getParameter(actionResponse.getNamespace()+"password1");
                String password2 =uploadRequest.getParameter(actionResponse.getNamespace()+"password2");
                logger.info(current+"   "+password1+"   "+password2);
                try {
                    long userId=UserLocalServiceUtil.authenticateForBasic(themeDisplay.getCompanyId(), "emailAddress", themeDisplay.getUser().getEmailAddress(), current);
                    if(themeDisplay.getUserId()!=userId)
                    {
                        throw new Exception("Invalid current password.");
                    }
                    if(!password1.equals(password2))
                    {
                        throw new Exception("Please confirm new password.");
                    }
                    UserLocalServiceUtil.updatePassword(userId, password1, password2, false);
    
                } catch (PortalException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SystemException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                catch (Exception e) {
                // TODO Auto-generated catch block
                    System.out.println(e.getMessage());
            }
    
            }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: