Fórumok

Create a landing page for non-logged-in users

Dan Scully, módosítva 11 év-val korábban

Create a landing page for non-logged-in users

Junior Member Bejegyzések: 48 Csatlakozás dátuma: 2011.10.13. Legújabb bejegyzések
Hi


is it possible to make liferay display a different landing page for logged-in users and the ones not logged in (e.g. guests) ?

So when a logged-in user enters www.portal.com she sees a normal front page, with portlets etc. but when an unlogged-in person enters www.portal.com she sees an alternate page, eg. requesting her to log in etc.

Is it possible?

I am using liferay-portal-6.1.0-ce-ga1
thumbnail
Apoorva Prakash, módosítva 11 év-val korábban

RE: Create a landing page for non-logged-in users

Liferay Master Bejegyzések: 658 Csatlakozás dátuma: 2010.06.15. Legújabb bejegyzések
Hello Dan,

I think there is no straight forward way, however it can be achieved by making some adjustments.

You can write and custom ServicePreAction class, where you can put a condition whether the user is signed in or not (themeDisplay.isSigedin()), and redirect to your required page.

Hope this may help for you.

Thanks and Regards,
Apoorva Prakash
Dan Scully, módosítva 11 év-val korábban

RE: Create a landing page for non-logged-in users

Junior Member Bejegyzések: 48 Csatlakozás dátuma: 2011.10.13. Legújabb bejegyzések
Which method should be overriden? Could you give a little bit more information on creating a custom class?
thumbnail
Apoorva Prakash, módosítva 11 év-val korábban

RE: Create a landing page for non-logged-in users

Liferay Master Bejegyzések: 658 Csatlakozás dátuma: 2010.06.15. Legújabb bejegyzések
Hello Dan,
package com.liferay.portal.events;
public class CustomServicePreAction extends Action {
	public void run(HttpServletRequest request, HttpServletResponse response) {
		String redirectUrl = PortalUtil.getPortalURL(request);
		    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
			if (!themeDisplay.isSignedIn()){
				response.sendRedirect(<privateurl>);
			}else{
				response.sendRedirect(<publicurl>);
			}
	    }
	}</publicurl></privateurl>


Make its entry in portal-ext.properties file.

You may also need to check with the current URL also, if there are more than pages for logged in and non-logged in users.
servlet.service.events.pre=com.liferay.portal.events.ServicePreAction,com.liferay.portal.events.CustomServicePreAction

Hope this will be helpful.

Thanks and Regards,
Apoorva Prakash
Dan Scully, módosítva 11 év-val korábban

RE: Create a landing page for non-logged-in users

Junior Member Bejegyzések: 48 Csatlakozás dátuma: 2011.10.13. Legújabb bejegyzések
Things start to work, but I here's the case

In my run method, I when I enter the portal and I use


String portalURL = PortalUtil.getPortalURL(request);
String url = request.getRequestURL().toString();


to get the request url (to check if you need to be signed in to view it) I get all kinds of urls and the base url of the portal
But the problem is that the request url is never equal to the portal url. I get different sufixes appended eg. /c/portal/layout or /c/portal/status while in the brower URL it clearly says: portal:8080 (w/o suffixes)

I need to differentiate only two cases: user wants to see the main page or any other page
Only the main page (viewable via http://portal.com, http://www.portal.com, http://portal.com:8080 etc...) should be secure..

Is it possible to check if the request regards the main page?
thumbnail
Apoorva Prakash, módosítva 11 év-val korábban

RE: Create a landing page for non-logged-in users

Liferay Master Bejegyzések: 658 Csatlakozás dátuma: 2010.06.15. Legújabb bejegyzések
Have a look on the following code, expecting your main page is - "/web/guest"...
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
String currentURL = ((themeDisplay.getLayout().isPrivateLayout()) ? PortalUtil.getPathFriendlyURLPrivateGroup() : 
				PortalUtil.getPathFriendlyURLPublic()) + themeDisplay.getScopeGroup().getFriendlyURL();
			
			String guestURL = "/web/guest";
			String redirectUrl = PortalUtil.getPortalURL(request);
			
			try{
				// redirection to user homepage, if logged in
				if(themeDisplay.isSignedIn() &amp;&amp; themeDisplay.getLayout().isPublicLayout() &amp;&amp; guestURL.equals(currentURL)){
						redirectUrl += "put your custom path here";
						response.sendRedirect(redirectUrl);
				}
			}catch(Exception e){
				e.printStackTrace();
			}


This will work.

Thanks and Regards,
Apoorva Prakash