掲示板

Liferay 6.2 How to customize landing page for different user based on role.

thumbnail
8年前 に Neha Goyal によって更新されました。

Liferay 6.2 How to customize landing page for different user based on role.

Regular Member 投稿: 121 参加年月日: 13/05/14 最新の投稿
Hi Guys,

I am currently working on Liferay 6.2 CE and EE and having a requirement to customize login action mechanism to decide landing site/page based on logged-in user 's role.
Any one have any idea how can i do so.Can any one tell me some steps.
I would be very much thankful.

Regards:
Neha
thumbnail
8年前 に Samuel Kong によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

Liferay Legend 投稿: 1902 参加年月日: 08/03/10 最新の投稿
thumbnail
8年前 に Meera Prince によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

Liferay Legend 投稿: 1111 参加年月日: 11/02/08 最新の投稿
Hi
Use custom landing hook it may help you.
https://www.liferay.com/marketplace/-/mp/application/17676547

Regards,
Meera Prince
thumbnail
8年前 に Miguel Pereira によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

New Member 投稿: 4 参加年月日: 14/05/23 最新の投稿
Hi Neha, the plugin that Meera suggested looks good!

One way to do this is with a hook. Have you had a chance to make one yet?
It can be challenging at first because the Liferay documentation is bloated and unspecific!

With a hook you can override some default Liferay properties as Samuel Kong was alluding to...
Two properties that are useful for this use case are:
login.events.post
logout.events.post

You can define your own Java class and set those properties to redirect users after they login or logout.

Some very useful links (second one has implementation code for the LoginPostAction)
http://proliferay.com/custom-action-liferay-hook/
https://www.liferay.com/community/forums/-/message_boards/message/7176708

Hope that helps!
thumbnail
8年前 に Meera Prince によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

Liferay Legend 投稿: 1111 参加年月日: 11/02/08 最新の投稿
Hi
Idea is something create one table there you can have columns like

RoleId | PageLayoutId | UserId | Priority | SiteId

1202(student) 1001 12345 1 1300

1203(Teacher) 1002 12345 2 1300


Create Post Login Action Hook in the run method write logic as follows

You will get User Id and from User Id and Site Id you can fetch Possible Landing pages to user and find priority Landing page then construct URL and redirect it.

This is my idea...it may help you..
Regards,
Meera Prince
thumbnail
8年前 に Neha Goyal によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

Regular Member 投稿: 121 参加年月日: 13/05/14 最新の投稿
Hi Meera,

Thanks for your suggestion.If you dont mind can you share me some sample code for above logic and can you share me that piece of code to redirect to landing page.

I would be thankful to you.

Regards:
Neha
thumbnail
8年前 に Arunjyoti Banik によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

Junior Member 投稿: 74 参加年月日: 14/08/26 最新の投稿
Hi Neha,

Follow these steps to update DeafultLandingPageAction.java
This action class gets invoked whenever user clicks on the submit button during Login. So where the user would land, should be predefined by updating this Action class.

Steps::

1. Create a simple hook project ............ that means choose hook while creating the project.
2. After hook is created, create a package and a class inside that package;
3. See the class name you want to override in portal.properties ............. in this case it will be DeafultLandingPageAction. Browse google to get the code, posted in github else from portal-impl.jar
4. Copy paste the entire code in your created class.
5. Give a sysout somewhere in the doRun();
6. Create a portal.properties through Liferay Hook Configuration;
7. In there, override this line, mandatorily::
login.events.post={your package name}.{your class name}
8. Deploy the hook.
9. On login with any user, you will now see your sysout in the console ....... which means your class is getting called instead of Liferay's DeafultLandingPageAction. Then write some logic to update the friendlyURL which you can see in the code <like if a user is mapped into Group then land him into a Group. If in Organisation, land into Organisation. But if in Organization and Group both, then prioritize Group coz there is no scope of navigation from Organisation to Group. >

Thanks
Arun
8年前 に LUCAS STICKLER によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

New Member 投稿: 12 参加年月日: 15/03/02 最新の投稿
Why are all of you so complicated.

First off, you can't do it based on a users "Role" because users can have many roles. If you do set those "Hooks" up you are going to eventually mess up your server or your users. Keep It Simple. If you REALLY want a hook, base it on an Organization or Group instead.

Otherwise, use what liferay has already given you...

https://docs.liferay.com/portal/6.2/propertiesdoc/portal.properties.html#Default Landing Page

In portal-ext.properties

To set the default landing page path for logged in users relative to the server path. This is the page users are automatically redirected to after logging in. For example, if you want the default landing page to be http://localhost:8080/web/guest/login, set this to /web/guest/login.

To activate this feature, set
auth.forward.by.last.path-true


To customize the behavior, see com.liferay.portal.events.DefaultLandingPageAction in the "login.events.post" property in Portal Events.

The following variables can be used: ${liferay:screenName} and ${liferay:userId}.
default.landing.page.path=/user/${liferay:screenName}/home


Not everything is complicated. Look at thing in the simplest way possible first. Then move to more complicated fixes.
You can even check to see if ${organization}/home works
thumbnail
8年前 に Neha Goyal によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

Regular Member 投稿: 121 参加年月日: 13/05/14 最新の投稿
Thanks every one...its done now.

Following code miught help any one
Create and hook and add following:
portal.properties
login.events.post=abc.xyz.liferay.hook.LandingPageAction
#Experience definition
site.priority.order=Agency Force,Corporate,Federation,SSC


LandingPageAction.java
package abc.xyz.liferay.hook;

import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;

import com.liferay.portal.kernel.struts.LastPath;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.User;

import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.kernel.util.WebKeys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.StringTokenizer;

public class LandingPageAction extends Action {


@Override
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
try {
HttpSession session = request.getSession();
User user = PortalUtil.getUser(request);
Group landingToGroup = getCommunityPriorityOrder(user);
String path = PortalUtil.getPortalProperties().get(PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING) + landingToGroup.getFriendlyURL();
LastPath lastPath = new LastPath(StringPool.BLANK, path);
session.setAttribute(WebKeys.LAST_PATH, lastPath);
} catch (Exception e) {
e.printStackTrace();
}
}

private Group getCommunityPriorityOrder(User user) throws ActionException {
Group landingToGroup = null;

try{
List<Group> userSiteList = user.getSiteGroups();
String communityPriorityOrder = (String) PortalUtil.getPortalProperties().get("site.priority.order");

if( userSiteList.size() > 0) {
landingToGroup = userSiteList.get(0);
}

StringTokenizer siteToken = new StringTokenizer(communityPriorityOrder,",");
while (siteToken.hasMoreElements()) {
String communityName = (String) siteToken.nextElement();
for(Group group :userSiteList){
if(group.getName().equalsIgnoreCase(communityName)){
landingToGroup = group;
return landingToGroup;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return landingToGroup;
}
}




Regards:
Neha
thumbnail
6年前 に Alessandro Lachina によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

New Member 投稿: 24 参加年月日: 13/06/12 最新の投稿
We had modify landing page action as sudgested.
What about if user close browser close and reopen it?!
It seems login action doesn't fired and user see first left page available.
Any idea to avoid it?

auth.forward.by.last.path-true seems to doesn't be used in this case.
Thanks
thumbnail
6年前 に Arunjyoti Banik によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

Junior Member 投稿: 74 参加年月日: 14/08/26 最新の投稿
By default, closing the browser and reopening it doesn't kill the session in which user is logged in. Try to make sure in the theme the following meta tags are present or not:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

Thanks and Regards
Arunjyoti Banik
6年前 に Kanwar Yuvraj Singh によって更新されました。

RE: Liferay 6.2 How to customize landing page for different user based on r

New Member 投稿: 10 参加年月日: 15/04/01 最新の投稿
LUCAS STICKLER:
Why are all of you so complicated.

First off, you can't do it based on a users "Role" because users can have many roles. If you do set those "Hooks" up you are going to eventually mess up your server or your users. Keep It Simple. If you REALLY want a hook, base it on an Organization or Group instead.

Otherwise, use what liferay has already given you...

https://docs.liferay.com/portal/6.2/propertiesdoc/portal.properties.html#Default Landing Page

In portal-ext.properties

To set the default landing page path for logged in users relative to the server path. This is the page users are automatically redirected to after logging in. For example, if you want the default landing page to be http://localhost:8080/web/guest/login, set this to /web/guest/login.

To activate this feature, set
auth.forward.by.last.path-true


To customize the behavior, see com.liferay.portal.events.DefaultLandingPageAction in the "login.events.post" property in Portal Events.

The following variables can be used: ${liferay:screenName} and ${liferay:userId}.
default.landing.page.path=/user/${liferay:screenName}/home


Not everything is complicated. Look at thing in the simplest way possible first. Then move to more complicated fixes.
You can even check to see if ${organization}/home works


Would this approach work if you want to send one site's user to /group/abc/landing-page and other site's users to /group/xyz/other-landing-page?