venerdì 21 settembre 2012

Liferay 6.1 Different Logout Page



When  we logout form Liferay the landing page is the company home. We can change it by setting the property  default.logout.page.path. Lets suppose we have 1-n communities and User belongs to all these communities and we want when user Sign Out from one community  should be redirected to the public page of that community.

A simple way to  achieve the goal  is to put a parameter referer to the sing out url. If you are using sing out link  in the dockbar  than we can create an hook to change this link.

The jsp where you have to change is /html/portlet/dockbar/view.jsp. You can render the original JSP into a string without overriding it so if the original jsp change there is no need to change your hook.
The sign out url is a property of ThemeDisplay and you need to change that property with your logout url, so we can take the group from the layout an check if has public page and the friendly url in that case we are going to change the link from /c/portal/logout to /c/portal/logout?referer=/web/community1.



<%@ include file="/html/portlet/dockbar/init.jsp" %>
 <%
     Group singOutGroup = layout.getGroup();
        String friendlyUrl=singOutGroup.getFriendlyURL();
     if (singOutGroup.hasPublicLayouts() && friendlyUrl != null) {
      String signOutUrl = themeDisplay.getURLSignOut()
        + "?referer=/web" + friendlyUrl;    
      themeDisplay.setURLSignOut(signOutUrl);
     }
%>   
 <liferay-util:buffer var="html">
  <liferay-util:include page="/html/portlet/dockbar/view.portal.jsp" />
 </liferay-util:buffer>  
 <%=html%>



If you don't use the dockbar you can change the signout url in the theme this way



#if ($is_signed_in)
#set ($myGroup = $theme_display.getScopeGroup())
#if($myGroup.hasPublicLayouts())
#set ($company_url = "/web"+$myGroup.getFriendlyURL())
#set ($sign_out_url = (($theme_display.getURLSignOut())+("?referer=")+$company_url))
#end
#end