Liferay Custom Login Implementation

       Liferay has been used for many years, and I always feel that I have recorded too few things. Now I feel that I still need to record it for later viewing. stop talking nonsense.

  •        Requirements: custom login implementation, liferay's original login interface is not beautiful, all want to customize it into the style you want
  •        Environment: Lliferay6.2G6, development framework SpringMVC
  •        Preview:
  •  
  •  Implementation idea: write a Portlet to control the login. I will not introduce the development of SpringMVC-portlet. There are many examples on the Internet. code directly.

     Control layer key code:

	/***
	 * Log in
	 * @param actionRequest
	 * @param actionResponse
	 */
	@ActionMapping(params = "action=loginCustom")
	public void loginCustom(ActionRequest actionRequest,ActionResponse actionResponse,Model model){
		String login = ParamUtil.getString(actionRequest, "login");
		String password = ParamUtil.getString(actionRequest, "password");
  		boolean authenticated = false;
		String feedbackMessageId = "fals";
		try {
			LoginUtilCompat.invokeLogin(PortalUtil.getHttpServletRequest(actionRequest),
					PortalUtil.getHttpServletResponse(actionResponse), login, password,
					false, CompanyConstants.AUTH_TYPE_SN);
			authenticated = true;
			actionResponse.sendRedirect("/group/-2/-1");//The address you want to redirect to after logging in. Liferay Portal has a configuration for redirecting after successful login. In this example, I wrote it directly
  			return;
		}
		catch (AuthException e) {
			feedbackMessageId = "authentication-failed";
		}
		catch (CompanyMaxUsersException e) {
			feedbackMessageId = "unable-to-login-because-the-maximum-number-of-users-has-been-reached";
		}
		catch (CookieNotSupportedException e) {
			feedbackMessageId = "authentication-failed-please-enable-browser-cookies";
		}
		catch (NoSuchUserException e) {
			feedbackMessageId = "authentication-failed";
		}
		catch (PasswordExpiredException e) {
			feedbackMessageId = "your-password-has-expired";
		}
		catch (UserEmailAddressException e) {
			feedbackMessageId = "authentication-failed";
		}
		catch (UserLockoutException e) {
			feedbackMessageId = "this-account-has-been-locked";
		}
		catch (UserPasswordException e) {
			feedbackMessageId = "authentication-failed";
		}
		catch (UserScreenNameException e) {
			feedbackMessageId = "authentication-failed";
		}
		catch (Exception e) {
			e.printStackTrace ();
		}
		try { //The parameter page corresponds to <%=portletSession.getAttribute("feedbackMessageId");%>
			actionRequest.getPortletSession().setAttribute("feedbackMessageId", feedbackMessageId, PortletSession.PORTLET_SCOPE);
 			actionResponse.sendRedirect("/");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace ();
		}
 }

 

  Next you need to have two configurations (important)

  1.    在liferay-portlet.xml中加入<private-session-attributes>false</private-session-attributes>
  2.    Add the property session.enable.phishing.protection=false to portal-setup-wizard.properties under the Liferay-portal directory

I won't post the page code, everyone implements a different interface,

Defined on the interface to get the login URL  

     <portlet:actionURL var="loginCustom">  <portlet:param name="action" value="loginCustom"/>   </portlet:actionURL>

      <form id="myForm"     action="${loginCustom}" method="post">
      //to do

       </form>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326249406&siteId=291194637