In Liferay 6 the default landing page can be set with the property default.landing.page.path
, but it is a general setting affecting each user in the portal instance.
To change the landing page of a user depending on the organization a custom action for the "post login" portal event is needed. Eventually, the property login.events.post
has to point to a custom login action:
login.events.post=yourcode.CustomLandingPageAction
There are two options to achieve this:
A custom action to make the user of an organization to land in the organization's private pages (derived from the links above):
public class CustomLandingPageAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
try {
doRun(request, response);
} catch (Exception e) {
throw new ActionException(e);
}
}
protected void doRun(HttpServletRequest request, HttpServletResponse response)
throws Exception {
long companyId = PortalUtil.getCompanyId(request);
String path = PrefsPropsUtil.getString(companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH);;
if (Validator.isNull(path)) {
User user = PortalUtil.getUser(request);
String language = user.getLocale().getLanguage();
List<Organization> orgList = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());
// Default landing page: go to the path in DefaultLandingPageAction
LastPath lastPath = new LastPath(StringPool.BLANK, path, new HashMap<String, String[]>());
// But if the logged user is in some community
if (!orgList.isEmpty()){
// and such community has a private page
if (orgList.get(0).hasPrivateLayouts()) {
// go there instead
String orgFriendlyURL = orgList.get(0).getGroup().getFriendlyURL();
String myPath = "/" + language + "/group" + orgFriendlyURL;
lastPath = new LastPath(StringPool.BLANK, myPath);
}
}
HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);
}
}
}