I'm using Liferay 6.0. I have multiple organizations and would like to change the user's landing page depending on organization.
I'm new to Liferay, tried to find some suggestions but could not find the correct answer.
Is it possible to do with out-of-the-box tools? without writing a code?
If code needed, what is the best solution?
Please help, Thank you
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With