Liferay一直在用到现在很多年了,总感觉自己记录的东西太少,现在觉得还是要记录下 方便以后查看了。废话不多说了。
- 需求:自定义登录实现,Liferay原本的登录界面之类的不美观,所有想要自定义成自己想要的风格
- 环境: Lliferay6.2G6,开发框架SpringMVC
- 预览:
-
- 实现思路:自写一个Portlet,来控制登录。SpringMVC-portlet的开发我就不做介绍了,这个在网上有很多例子。直接上代码。
控制层关键代码:
/*** * 登录 * @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");//登录后想要跳转的地址,Liferay Portal有关于登录成功后跳转的配置,本例中我直接写固定了 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 { //传参数 页面对应 <%=portletSession.getAttribute("feedbackMessageId");%> actionRequest.getPortletSession().setAttribute("feedbackMessageId", feedbackMessageId, PortletSession.PORTLET_SCOPE); actionResponse.sendRedirect("/"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
接下来需要有两个配置(重要)
- 在liferay-portlet.xml中加入<private-session-attributes>false</private-session-attributes>
- 在Liferay-portal目录下面 portal-setup-wizard.properties 加入属性 session.enable.phishing.protection=false
页面代码我就不贴了,每个人实现的界面不一样,
界面上定义 获取登录URL
<portlet:actionURL var="loginCustom"> <portlet:param name="action" value="loginCustom"/> </portlet:actionURL>
<form id="myForm" action="${loginCustom}" method="post">
//to do
</form>