留言板

Redirect Users in a specific role to a specific page after they logged in

Carl K,修改在10 年前。

Redirect Users in a specific role to a specific page after they logged in

New Member 帖子: 11 加入日期: 13-11-13 最近的帖子
Hi,

I recently got a requirement to redirect users in a specific role to a specific page on my site. I have gone to a number of the posts but still couldn't find a solution for this requirement and I knew that there is a simple way to solve it.

My site I created have a number of pages and different users have different permissions to access them. What I could like to do is redirect users for example, a teacher will be automatically gone to teacher page after he/she logged in (this is no private page for a specific user). Also, once the teacher has logged in they could see other pages on the menu bar like other who are in the same role.

As what I can see from posts, they have mentioned about public and private pages for an organisation or an user but nothing about Role which hasn't got a private or public page to access through.

Please kindly give me an advice.

Regards,
Carl
thumbnail
meera prince,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Liferay Legend 帖子: 1111 加入日期: 11-2-8 最近的帖子
Hi
Get Custom landing page hook and customize .
Thing like create one table and there you have columns like userId, groupId,layoutId and rank.
for each user we need to configure his landing page layout id.
go to custom landing page hook based on your requirement like for site user,organization user or usergroup
you need write some logic in appropriate class there you need get layout id from our configuration table based on current organization/site nothing but group id and need to redirect to that layout.
the following is classes you may need to write logic

https://github.com/opensourceforlife/CustomLandingPage-Hook/tree/master/src/main/java/com/liferay/opensourceforlife/landingpage

The following is link

https://www.liferay.com/marketplace/-/mp/application/17676547

Regards,
meera prince
thumbnail
Tejas Kanani,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Liferay Master 帖子: 654 加入日期: 09-1-6 最近的帖子
Thanks Meera for the details.

Carl,
As Meera has already covered the details regarding Custom Landing Page Hook.
Little updates - Good news is, If you are using Liferay 6.2, I've already updated the Custom Landing Page Hook supports Role & User Group based landing in it's latest version(v1.2.2).
I've already submitted the new version to Liferay Marketplace. As It's currently under review state, you'll not be able to download it until it got approved.

You can also download the latest version WAR(CustomLandingPage-hook-1.2.2.war) from https://github.com/opensourceforlife/CustomLandingPage-Hook/releases
And for more details visit Read Me from Custom Landing Page Hook Github Repository.

Best Regards,
Tejas
Carl K,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

New Member 帖子: 11 加入日期: 13-11-13 最近的帖子
Hi Tejas,

Thank you so much. I am glad to hear this good news, and look forward to seeing the new version.

Regards,
Carl
thumbnail
Daniel Tyger,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Regular Member 帖子: 105 加入日期: 13-2-6 最近的帖子
Tejas,

We are looking to create a matrix of several options for landing pages, depending on which user groups a person is member of...:

If we could set a list of corresponding user groups <> landing pages somewhere, that would be awesome. It's ok with us if the first match is where the user is redirected...:

If in... ------------->>>>>>>>>>>> Go to...
User Group ------------->>>>>>>>>>>> Landing Page
LAW ------------->>>>>>>>>>>> /group/law/home
Business ------------->>>>>>>>>>>> /group/business/home
Psychology ------------->>>>>>>>>>>> /group/psychology/home
etc....
ELSE land user on /group/guest/home...

Is this possible with your new release?

Thank you for your work and attention to the community. -daniel
thumbnail
Tejas Kanani,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Liferay Master 帖子: 654 加入日期: 09-1-6 最近的帖子
Daniel,

One way you can achieve this is, Create LAW, Business & Psychology User groups/Roles, whatever suits for you.
And then define specific landing page for each user group/role as a custom attribute with name "landingPage"of respective type. (Available only for Liferay 6.2+ as it supports custom attribute for user group & role)

For more details,
from https://www.liferay.com/marketplace/-/mp/application/17676547
Role/UserGroup
- Create custom attribute of type "TextField" with key "landingPage" and define value as desired page's complete page URL. i.e. /web/mysite/myhome


So upon login, based on user's membership of user group/role, it will be redirected to specific page. But if user belongs to more than one user group/role, it will pick the first and land on page accordingly.

Hope this is what you are looking for OR maybe I can take your some what near to what you need.

Feel free to revert back if any questions/concerns.

Thanks,
Tejas
thumbnail
Daniel Tyger,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Regular Member 帖子: 105 加入日期: 13-2-6 最近的帖子
Hi Tejas,

That sounds perfect. Thank you for replying - i am grateful. I have set up your hook in Liferay IDE, as shown, adjusted the properties and also added the Custom Attribute landingPage key to User Groups. The hook deploys fine, and all seems well...but not working. I read through the comments on your website and then... I also checked that Control Panel > Settings, I removed the default landing page there. Cleaned /temp /work and restarted, still not landing on custom page.

The users I am testing are definitely members of the user group and the attribute set for that group...

Still, the hook does not seem to work. I am supplying some images, so maybe you see a clue where I went wrong.

Check my attachments, here...

Any thought why I am still not landing on the desired custom page?
thumbnail
Tejas Kanani,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Liferay Master 帖子: 654 加入日期: 09-1-6 最近的帖子
As mentioned in my last reply, If user belongs to more than one group it will pick the first group from list and check for the landing page key for that group only.
But if user belongs to more than one user group/role, it will pick the first and land on page accordingly.

So here it looks your user belongs to more than one group and at the same time it might have taken other group and checked for the landing page custom attribute and if found none/blank it will go with default landing page.

I would like you to try once by removing all other groups other than UMF. If still doesn't work, follow the steps mentioned in below post and send the logs file.
https://www.liferay.com/community/forums/-/message_boards/message/36133113

Again this would be the limitation for user being member of multiple user groups/roles. And in that case it will pick the first from the list and not a specific user group/role.

Hope this helps.

Thanks.
Tejas
thumbnail
Daniel Tyger,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Regular Member 帖子: 105 加入日期: 13-2-6 最近的帖子
I see... I did try this - removing the groups except UMF, but still not working...

Anyway, this (first group only approach) will not accommodate our situation for several reasons. Most users have many groups but only one "Primary Landing Site" group, which we hope to drive the custom landing page post-login. Indeed, users must also be a member of one of many groups to be a member of a site / community... and often has other memberships due to various affiliations they may have...

What we would need is a bit different approach I guess, where all of the user's groups are fetched and then a list of primary landing sites / groups in a hash map or something and pick the first one that applies. There are only about 10 primary landing pages to define. So, a list of groups / landing page urls could be very limited or even be pre-defined properties. Each user is a member of only one primary landing site group, but some users may not be in any of those and it is ok if they land on guest/home...

Any thoughts on how we might achieve this?

Thank you again for your inputs.
thumbnail
Tejas Kanani,修改在10 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Liferay Master 帖子: 654 加入日期: 09-1-6 最近的帖子
There will always be a new requirement each time you work on different things. So even in your case, it's something which is not covered in general scenarios and you need to customize the code which covers your need as per your requirement.
Feel free to fork/use the code and make modifications. That's the flexibility you would get in Open Source App emoticon !!!
where all of the user's groups are fetched and then a list of primary landing sites / groups in a hash map or something and pick the first one that applies. There are only about 10 primary landing pages to define. So, a list of groups / landing page urls could be very limited or even be pre-defined properties.

And I guess you already have an Idea on how to accommodate this changes. And may be you can drive your list of primary landing pages via properties file or via custom attribute. Just a thought !!
I'll surely take this scenario in consideration while working on/releasing next version.

Thanks,
Tejas
thumbnail
Daniel Tyger,修改在9 年前。

RE: Redirect Users in a specific role to a specific page after they logged

Regular Member 帖子: 105 加入日期: 13-2-6 最近的帖子
Tejas Kanani:
There will always be ...
Thanks,
Tejas


A solution to the issues raised here where the Landing Page Configuration tool, when configured properly, still was not working, is found in this thread:

https://www.liferay.com/community/forums/-/message_boards/message/38225349

And, if you'd like to save the trip, you need to empty the Portal Configuration >> Portal Settings >> Home URL field and Default Landing Page field to test if you LAST_PATH override is working or not.

Thanks to you, Tejas for the CLP hook!