@Override
  public void postProcess(
      long companyId, PortletRequest portletRequest, PortletPreferences portletPreferences)
      throws SystemException {

    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailFromAddress",
        LoginUtil.getEmailFromName(portletPreferences, companyId));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailFromName",
        LoginUtil.getEmailFromName(portletPreferences, companyId));

    String languageId = LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault());

    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordResetBody_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_RESET_BODY));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordResetSubject_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_RESET_SUBJECT));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordSentBody_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_SENT_BODY));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordSentSubject_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_SENT_SUBJECT));
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HeaderCacheServletResponse headerCacheServletResponse = null;

    if (response instanceof HeaderCacheServletResponse) {
      headerCacheServletResponse = (HeaderCacheServletResponse) response;
    } else {
      headerCacheServletResponse = new HeaderCacheServletResponse(response);
    }

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

    Layout layout = themeDisplay.getLayout();

    Boolean layoutDefault = (Boolean) request.getAttribute(WebKeys.LAYOUT_DEFAULT);

    if ((layoutDefault != null) && (layoutDefault.booleanValue())) {
      Layout requestedLayout = (Layout) request.getAttribute(WebKeys.REQUESTED_LAYOUT);

      if (requestedLayout != null) {
        String redirectParam = "redirect";

        if (Validator.isNotNull(PropsValues.AUTH_LOGIN_PORTLET_NAME)) {
          redirectParam =
              PortalUtil.getPortletNamespace(PropsValues.AUTH_LOGIN_PORTLET_NAME) + redirectParam;
        }

        String authLoginURL = null;

        if (PrefsPropsUtil.getBoolean(
            themeDisplay.getCompanyId(),
            PropsKeys.CAS_AUTH_ENABLED,
            PropsValues.CAS_AUTH_ENABLED)) {

          authLoginURL = themeDisplay.getURLSignIn();
        }

        if (Validator.isNull(authLoginURL)) {
          authLoginURL = PortalUtil.getCommunityLoginURL(themeDisplay);
        }

        if (Validator.isNull(authLoginURL)) {
          authLoginURL = PropsValues.AUTH_LOGIN_URL;
        }

        if (Validator.isNull(authLoginURL)) {
          PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid());

          authLoginURL = loginURL.toString();
        }

        String currentURL = PortalUtil.getCurrentURL(request);

        authLoginURL = HttpUtil.setParameter(authLoginURL, redirectParam, currentURL);

        if (_log.isDebugEnabled()) {
          _log.debug("Redirect requested layout to " + authLoginURL);
        }

        headerCacheServletResponse.sendRedirect(authLoginURL);
      } else {
        String redirect = PortalUtil.getLayoutURL(layout, themeDisplay);

        if (_log.isDebugEnabled()) {
          _log.debug("Redirect default layout to " + redirect);
        }

        headerCacheServletResponse.sendRedirect(redirect);
      }

      return null;
    }

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (_log.isDebugEnabled()) {
      _log.debug("p_l_id is " + plid);
    }

    if (plid > 0) {
      ActionForward actionForward =
          processLayout(mapping, request, headerCacheServletResponse, plid);

      String contentType = response.getContentType();

      CacheResponseUtil.setHeaders(response, headerCacheServletResponse.getHeaders());

      if (contentType != null) {
        response.setContentType(contentType);
      }

      return actionForward;
    } else {
      try {
        forwardLayout(request);

        return mapping.findForward(ActionConstants.COMMON_FORWARD_JSP);
      } catch (Exception e) {
        PortalUtil.sendError(e, request, headerCacheServletResponse);

        CacheResponseUtil.setHeaders(response, headerCacheServletResponse.getHeaders());

        return null;
      }
    }
  }
  protected void login(
      ThemeDisplay themeDisplay,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      PortletPreferences preferences)
      throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    String authType = preferences.getValue("authType", null);

    // cusotm code =============
    try {
      User tmp = null;
      UserEntry userEntryTmp = null;
      if (Validator.isEmailAddress(login)) {
        tmp = UserLocalServiceUtil.getUserByEmailAddress(PortalUtil.getCompanyId(request), login);
        login = String.valueOf(tmp.getUserId());
        System.out.println("email:" + login);
      } else if (Validator.isNumber(login)) {
        // is mobile number
        //				UserEntryLocalServiceUtil.get
        userEntryTmp = UserEntryLocalServiceUtil.findByMobilePhone(login);
        login = String.valueOf(userEntryTmp.getUserId());
        System.out.println("mobile number:" + login);
      } else {
        // userEntryTmp = UserEntryLocalServiceUtil.findByUserName(login);
        tmp = UserLocalServiceUtil.getUserByScreenName(PortalUtil.getCompanyId(request), login);
        login = String.valueOf(tmp.getUserId());
        System.out.println("userName:"******"/portal/protected");
    } else {
      String redirect = ParamUtil.getString(actionRequest, "redirect");

      if (Validator.isNotNull(redirect)) {
        redirect = PortalUtil.escapeRedirect(redirect);

        if (!redirect.startsWith(Http.HTTP)) {
          redirect = getCompleteRedirectURL(request, redirect);
        }

        actionResponse.sendRedirect(redirect);
      } else {
        boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

        if (doActionAfterLogin) {
          return;
        } else {
          actionResponse.sendRedirect(themeDisplay.getPathMain());
        }
      }
    }
  }