Foros de discusión
Dynamic Landing Page, based on user's organisation
M. Garcia, modificado hace 13 años.
Dynamic Landing Page, based on user's organisation
Regular Member Mensajes: 107 Fecha de incorporación: 17/5/11 Mensajes recientes
Hi folks,
I'm using LR 6.0.6.
I'd like to redirect my users after login on their organisation's site, i.e. set a dynamic landing page based on the organisation a user belongs to.
So far I found no "easy way" to achieve this...
What would be the proper way ? I found this wiki page, but it's based on Liferay 4.3, and I guess there's been quite important architecture changes, so I doubt it's still the best practice.
So far I found those solutions :
Any enlightment ? =)
PS: my users belongs to ONE organization, as encouraged.
I'm using LR 6.0.6.
I'd like to redirect my users after login on their organisation's site, i.e. set a dynamic landing page based on the organisation a user belongs to.
So far I found no "easy way" to achieve this...
What would be the proper way ? I found this wiki page, but it's based on Liferay 4.3, and I guess there's been quite important architecture changes, so I doubt it's still the best practice.
So far I found those solutions :
- modify DefaultLandingPageAction.java (LR Core), and override path variable, as suggested in the wiki page. (doesn't feel like right).
- write a hook for the login portlet
- or... magical solution ?
Any enlightment ? =)
PS: my users belongs to ONE organization, as encouraged.
Jonas Yuan, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation (Respuesta)
Liferay Master Mensajes: 993 Fecha de incorporación: 27/4/07 Mensajes recientes
Hi M. Garcia,
You may leverage hooks (portal properties hooks, specifically).
Thanks
Jonas Yuan
You may leverage hooks (portal properties hooks, specifically).
Thanks
Jonas Yuan
Samuel Kong, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation (Respuesta)
Liferay Legend Mensajes: 1902 Fecha de incorporación: 10/3/08 Mensajes recientes
The best way is option 1. Create a new LandingPageAction class. You should not directly modify DefaultLandingPageAction. You also don't actually want to "override" the path variable. All you need your class to do is perform whatever logic you want. Then call
session.setAttribute(WebKeys.LAST_PATH, yourPathHere)
where yourPathHere is the path to wherever you want to redirect the user to.
session.setAttribute(WebKeys.LAST_PATH, yourPathHere)
where yourPathHere is the path to wherever you want to redirect the user to.
Jan Gregor, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation (Respuesta)
Regular Member Mensajes: 224 Fecha de incorporación: 20/10/10 Mensajes recientes
Hi,
The only thing you need to do is to create a hook with PostLoginAction class including the mentioned code for setting the last path. Do not forget to enable the property in portal-ext.properties. More infos can be found at the link, which you already mentioned.
Regards,
Jan.
The only thing you need to do is to create a hook with PostLoginAction class including the mentioned code for setting the last path. Do not forget to enable the property in portal-ext.properties. More infos can be found at the link, which you already mentioned.
Regards,
Jan.
M. Garcia, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation
Regular Member Mensajes: 107 Fecha de incorporación: 17/5/11 Mensajes recientes
Thanks everyone !
I tried to make a hook as you mentioned, but build fails :
Here's my liferay-hook.xml :
My portal.properties in docroot/WEB-INF/src :
My LandingPageAction.java, in docroot\WEB-INF\src\com\liferay\my :
What am I doing wrong ?
I tried to make a hook as you mentioned, but build fails :
D:\workspace\liferay-plugins-sdk-6.0.6-20110225\hooks\landing-page-hook>ant deploy
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: D:\workspace\liferay-plugins-sdk-6.0.6-20110225\hooks\landing-page-hook\build.xml
compile:
merge:
compile-java:
[javac] Compiling 1 source file to D:\workspace\liferay-plugins-sdk-6.0.6-20110225\hooks\landing-page-hook\docroot\WEB-INF\classes
BUILD FAILED
D:\workspace\liferay-plugins-sdk-6.0.6-20110225\build-common-plugin.xml:347: The following error occurred while executing this line:
D:\workspace\liferay-plugins-sdk-6.0.6-20110225\build-common.xml:90: Error running javac.exe compiler
Total time: 0 seconds
Here's my liferay-hook.xml :
<!--?xml version="1.0"?-->
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>
My portal.properties in docroot/WEB-INF/src :
login.events.post=[b]com.liferay.my.LandingPageAction[/b]
My LandingPageAction.java, in docroot\WEB-INF\src\com\liferay\my :
package com.liferay.my;
public class LandingPageAction extends Action {
private static Log _log = LogFactoryUtil.getLog(LandingPageAction.class);
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 (_log.isInfoEnabled()) {
_log.info(PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
}
if (Validator.isNotNull(path)) {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
User user = themeDisplay.getUser();
long userId = themeDisplay.getUserId();
String language = user.getLocale().getLanguage();
List<organization> orgList = OrganizationLocalServiceUtil.getUserOrganizations(userId);
String orgFriendlyURL = orgList.get(0).getGroup().getFriendlyURL();
String myPath = "/"+language+"/group/"+orgFriendlyURL;
LastPath lastPath = new LastPath(StringPool.BLANK, myPath);
HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);
}
}
}</organization>
What am I doing wrong ?
Jan Gregor, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation (Respuesta)
Regular Member Mensajes: 224 Fecha de incorporación: 20/10/10 Mensajes recientes
D:\workspace\liferay-plugins-sdk-6.0.6-20110225\build-common.xml:90: Error running javac.exe compiler
try to run javac in your command prompt, if works, check your jdk config in sdk, if not works, check the jdk installation
Regards,
Jan.
try to run javac in your command prompt, if works, check your jdk config in sdk, if not works, check the jdk installation
Regards,
Jan.
Jan Gregor, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation
Regular Member Mensajes: 224 Fecha de incorporación: 20/10/10 Mensajes recientes
jdk - liferay sdk configuration.
Regards,
Jan.
Regards,
Jan.
M. Garcia, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation
Regular Member Mensajes: 107 Fecha de incorporación: 17/5/11 Mensajes recientes
Ok this error was indeed due to jdk, thanks Jan.
M. Garcia, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation
Regular Member Mensajes: 107 Fecha de incorporación: 17/5/11 Mensajes recientes
Okey I'm almost done it seems, still I don't get what happens now.
In the doRun() of my LandingPageAction (see above), I get a null pointer at this line :
I can't retrieve the ThemeDisplay... needed to get the user and his/her organization(s).
In the doRun() of my LandingPageAction (see above), I get a null pointer at this line :
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
I can't retrieve the ThemeDisplay... needed to get the user and his/her organization(s).
Jan Gregor, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation (Respuesta)
Regular Member Mensajes: 224 Fecha de incorporación: 20/10/10 Mensajes recientes
For retrieving user in context of a post login action please use :
User currentUser = PortalUtil.getUser(request);
Regards,
Jan.
User currentUser = PortalUtil.getUser(request);
Regards,
Jan.
M. Garcia, modificado hace 13 años.
RE: Dynamic Landing Page, based on user's organisation (Respuesta)
Regular Member Mensajes: 107 Fecha de incorporación: 17/5/11 Mensajes recientes
Thanks a lot Jan, it's all good =)
For those interested, my LandingPageAction :
For those interested, my LandingPageAction :
public class LandingPageAction extends Action {
private static Log _log = LogFactoryUtil.getLog(LandingPageAction.class);
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 (_log.isInfoEnabled()) {
_log.info(PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL
+ path);
}
if (Validator.isNotNull(path)) {
User user = PortalUtil.getUser(request);
String language = user.getLocale().getLanguage();
List<organization> orgList = OrganizationLocalServiceUtil
.getUserOrganizations(user.getUserId());
// if org has private pages, redirect to them
if (orgList.get(0).hasPrivateLayouts()) {
String orgFriendlyURL = orgList.get(0).getGroup()
.getFriendlyURL();
String myPath = "/" + language + "/group" + orgFriendlyURL;
LastPath lastPath = new LastPath(StringPool.BLANK, myPath);
HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);
}
// else default action (same as DefaultLandingPageAction)
else {
LastPath lastPath = new LastPath(
StringPool.BLANK, path, new HashMap<string, string[]>());
HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);
}
}
}
}</string,></organization>
Tim Telcik, modificado hace 11 años.
RE: Dynamic Landing Page, based on user's organisation
New Member Mensajes: 9 Fecha de incorporación: 1/4/10 Mensajes recientes
Hello M. Garcia,
just in case this is still an issue for developers, or people stumble across this issue now (July 2013), you may want to look at the following solution in the Liferay Marketplace for Liferay Portal 6.1 and later :
Liferay Marketplace - Custom Landing Page Hook
http://www.liferay.com/marketplace/-/mp/application/17676547?_7_WAR_osbportlet_backURL=%2Fmarketplace%3F_11_WAR_osbportlet_formDate%3D1374818080789%26p_p_id%3D7_WAR_osbportlet%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_col_id%3Dcolumn-1%26p_p_col_pos%3D1%26p_p_col_count%3D3%26_7_WAR_osbportlet_mvcPath%3D%252Fmarketplace%252Fsearch.jsp%26p_r_p_564233524_assetCategoryId%3D0%26p_r_p_564233524_keywords%3Dlanding%2Bpage]
Regards,
Tim
just in case this is still an issue for developers, or people stumble across this issue now (July 2013), you may want to look at the following solution in the Liferay Marketplace for Liferay Portal 6.1 and later :
Liferay Marketplace - Custom Landing Page Hook
http://www.liferay.com/marketplace/-/mp/application/17676547?_7_WAR_osbportlet_backURL=%2Fmarketplace%3F_11_WAR_osbportlet_formDate%3D1374818080789%26p_p_id%3D7_WAR_osbportlet%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_col_id%3Dcolumn-1%26p_p_col_pos%3D1%26p_p_col_count%3D3%26_7_WAR_osbportlet_mvcPath%3D%252Fmarketplace%252Fsearch.jsp%26p_r_p_564233524_assetCategoryId%3D0%26p_r_p_564233524_keywords%3Dlanding%2Bpage]
Regards,
Tim
Igor Brittner, modificado hace 5 años.
RE: Dynamic Landing Page, based on user's organisation
New Member Mensajes: 20 Fecha de incorporación: 3/7/19 Mensajes recientes
Hey guys,
I know this is over 5 years old, but I am struggling with the exact same problem.
Since I've never coded a single line (except for some basic batch scripting), I do not understand how this hook process works. I downloaded the Custom Landing Page Hook and configured my portal-ext.properties accordingly. All the settings seem to be right (according to the manual), but somehow I get redirected to /user/admin with the error "required ressource could not be found", because I dont use private pages.
Some something must overwrite my settings and I get redirected to the mentioned "URL". Doesnt matter what I edit, nothing seems to work.
Anybody has an idea?
I know this is over 5 years old, but I am struggling with the exact same problem.
Since I've never coded a single line (except for some basic batch scripting), I do not understand how this hook process works. I downloaded the Custom Landing Page Hook and configured my portal-ext.properties accordingly. All the settings seem to be right (according to the manual), but somehow I get redirected to /user/admin with the error "required ressource could not be found", because I dont use private pages.
Some something must overwrite my settings and I get redirected to the mentioned "URL". Doesnt matter what I edit, nothing seems to work.
Anybody has an idea?
Suresh Nimmakayala, modificado hace 5 años.
RE: Dynamic Landing Page, based on user's organisation
Liferay Master Mensajes: 690 Fecha de incorporación: 18/8/04 Mensajes recientes
please mention what version you using ! assuming 7.x , create a customLanding module in LoginPostAction write your Business logic to generate user landing page path