Foren

Dynamic Landing Page, based on user's organisation

thumbnail
M. Garcia, geändert vor 12 Jahren.

Dynamic Landing Page, based on user's organisation

Regular Member Beiträge: 107 Beitrittsdatum: 17.05.11 Neueste Beiträge
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 :

  • 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.
thumbnail
Jonas Yuan, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation (Antwort)

Liferay Master Beiträge: 993 Beitrittsdatum: 27.04.07 Neueste Beiträge
Hi M. Garcia,

You may leverage hooks (portal properties hooks, specifically).

Thanks

Jonas Yuan
thumbnail
Samuel Kong, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation (Antwort)

Liferay Legend Beiträge: 1902 Beitrittsdatum: 10.03.08 Neueste Beiträge
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.
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation (Antwort)

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
thumbnail
M. Garcia, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation

Regular Member Beiträge: 107 Beitrittsdatum: 17.05.11 Neueste Beiträge
Thanks everyone !

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 ?
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation (Antwort)

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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.
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
jdk - liferay sdk configuration.

Regards,
Jan.
thumbnail
M. Garcia, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation

Regular Member Beiträge: 107 Beitrittsdatum: 17.05.11 Neueste Beiträge
Ok this error was indeed due to jdk, thanks Jan.
thumbnail
M. Garcia, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation

Regular Member Beiträge: 107 Beitrittsdatum: 17.05.11 Neueste Beiträge
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 :
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);


I can't retrieve the ThemeDisplay... needed to get the user and his/her organization(s).
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation (Antwort)

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
For retrieving user in context of a post login action please use :

User currentUser = PortalUtil.getUser(request);

Regards,

Jan.
thumbnail
M. Garcia, geändert vor 12 Jahren.

RE: Dynamic Landing Page, based on user's organisation (Antwort)

Regular Member Beiträge: 107 Beitrittsdatum: 17.05.11 Neueste Beiträge
Thanks a lot Jan, it's all good =)

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>
thumbnail
Tim Telcik, geändert vor 10 Jahren.

RE: Dynamic Landing Page, based on user's organisation

New Member Beiträge: 9 Beitrittsdatum: 01.04.10 Neueste Beiträge
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
Igor Brittner, geändert vor 4 Jahren.

RE: Dynamic Landing Page, based on user's organisation

New Member Beiträge: 20 Beitrittsdatum: 03.07.19 Neueste Beiträge
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?
thumbnail
Suresh Nimmakayala, geändert vor 4 Jahren.

RE: Dynamic Landing Page, based on user's organisation

Liferay Master Beiträge: 690 Beitrittsdatum: 18.08.04 Neueste Beiträge
please mention what version you using ! assuming 7.x , create a customLanding module&nbsp; &nbsp;in LoginPostAction&nbsp; write your&nbsp;Business logic to generate user landing page path