Example usage for com.liferay.portal.kernel.model User getPasswordPolicy

List of usage examples for com.liferay.portal.kernel.model User getPasswordPolicy

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model User getPasswordPolicy.

Prototype

public PasswordPolicy getPasswordPolicy() throws com.liferay.portal.kernel.exception.PortalException;

Source Link

Usage

From source file:com.liferay.users.admin.web.internal.portlet.action.UpdatePasswordMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    try {/*  ww w  . j  a  v  a  2 s  .  c  o m*/
        User user = _portal.getSelectedUser(actionRequest);

        String newPassword1 = actionRequest.getParameter("password1");
        String newPassword2 = actionRequest.getParameter("password2");

        boolean passwordReset = ParamUtil.getBoolean(actionRequest, "passwordReset");

        PasswordPolicy passwordPolicy = user.getPasswordPolicy();

        if ((user.getLastLoginDate() == null) && ((passwordPolicy == null)
                || (passwordPolicy.isChangeable() && passwordPolicy.isChangeRequired()))) {

            passwordReset = true;
        }

        String reminderQueryQuestion = BeanParamUtil.getString(user, actionRequest, "reminderQueryQuestion");

        if (reminderQueryQuestion.equals(UsersAdmin.CUSTOM_QUESTION)) {
            reminderQueryQuestion = BeanParamUtil.getStringSilent(user, actionRequest,
                    "reminderQueryCustomQuestion");
        }

        String reminderQueryAnswer = BeanParamUtil.getString(user, actionRequest, "reminderQueryAnswer");

        if (Validator.isNotNull(newPassword1) || Validator.isNotNull(newPassword2)) {

            _userLocalService.updatePassword(user.getUserId(), newPassword1, newPassword2, passwordReset);
        }

        _userLocalService.updatePasswordReset(user.getUserId(), passwordReset);

        if (Validator.isNotNull(reminderQueryQuestion) && Validator.isNotNull(reminderQueryAnswer)) {

            _userLocalService.updateReminderQuery(user.getUserId(), reminderQueryQuestion, reminderQueryAnswer);
        }

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if ((user.getUserId() == themeDisplay.getUserId()) && PropsValues.SESSION_STORE_PASSWORD
                && Validator.isNotNull(newPassword1)) {

            PortletSession portletSession = actionRequest.getPortletSession();

            portletSession.setAttribute(WebKeys.USER_PASSWORD, newPassword1, PortletSession.APPLICATION_SCOPE);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass());

            actionResponse.setRenderParameter("mvcPath", "/error.jsp");
        } else if (e instanceof UserPasswordException) {
            SessionErrors.add(actionRequest, e.getClass(), e);

            String redirect = _portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

            if (Validator.isNotNull(redirect)) {
                sendRedirect(actionRequest, actionResponse, redirect);
            }
        } else {
            throw e;
        }
    }
}