!!!! DOWNLOAD "OS4L Custom Landing Page Hook" from Liferay Market Place now !!!!
Update : Also check OS4L Custom Landing Page Hook for complete solution of Landing page.
Hi Guys,
I've seen so many question going around landing on custom page after user log in in Liferay based on Organization/Site membership. So today I am going to cover the same thing and show you how can we achieve the same.
We can achieve this using Liferay Hook. I am using Liferay 6.1 CE GA1 for creating hook. If you don't have source for Liferay 6.1 CE GA1, you can download it from the given link.
Now first thing is we need create hook. Refer my other blog regarding Create Liferay Hook using Liferay IDE if you have never used it before.
We'll create our custom Action class which will be executed after user logs in successfully.
Override portal.properties
- First we'll have to override portal.properties's login.events.post property.
- Open liferay-hook.xml using Liferay Hook Editor. Select Hook Configuration-->Portal Properties
- Check Customize Liferay Portal Properties and Create new portal.properties
- From Portal Properties Overrides, Add Portal Property
Name - login.events.post
Value - com.liferay.opensourceforlife.events.CustomLandingPageAction
- Save it.
Create CustomLandingPageAction
- Create CustomLandingPageAction class in com.liferay.opensourceforlife.events package.
- It extends com.liferay.portal.kernel.events.Action.
- Now main logic is we'll have to set LAST_PATH session attribute which holds the landing page path which will be used after user logs in to Liferay. So just create your path on which you want user to land.
HttpSession session = request.getSession(); session.setAttribute(WebKeys.LAST_PATH, new LastPath( StringPool.BLANK, path));
Organization landing path
- Use below function to get organization path which user is member of.
private String getOrganizationPath(User user, boolean includeLanguage)
throws PortalException, SystemException {
String organizationPath = StringPool.BLANK;
List<Organization> userOrganizations = user.getOrganizations();
String language = StringPool.BLANK;
if (includeLanguage) {
language = StringPool.SLASH + user.getLocale().getLanguage();
}
if ((userOrganizations != null) && !userOrganizations.isEmpty()) {
String organizationFriendlyURL =
userOrganizations.get(0).getGroup().getFriendlyURL();
organizationPath = language + "/web" + organizationFriendlyURL;
}
return organizationPath;
}
- If you have change in requirement, you can modify it according.
Site Lading Path
- Use below function to get site path which user is member of.
private String getSitePath(User user, boolean includeLanguage)
throws PortalException, SystemException {
String sitePath = StringPool.BLANK;
List<Group> userSites = getSites(user.getUserId());
String language = StringPool.BLANK;
if (includeLanguage) {
language = StringPool.SLASH + user.getLocale().getLanguage();
}
if ((userSites != null) && !userSites.isEmpty()) {
String siteFriendlyURL = userSites.get(0).getFriendlyURL();
sitePath = language + "/web" + siteFriendlyURL;
}
return sitePath;
}
- If you have change in requirement, you can modify it according.
- You can download full source code and package war.
Downloads
Downloads
To download the Source Code OR WAR, simply pay by add a tweet on Twitter or Facebook comment and let other know regarding this cool blog.
- Source Code
- War
Reference Blogs
I hope this will be helpful.
Please revert back if you find any issue or need any help.
Thanks & Regards,
Tejas Kanani
Recognition - Liferay Contributor Award-2012
