Foren

How does one redirect a user to his previous page after login?

lsli lsli, geändert vor 13 Jahren.

How does one redirect a user to his previous page after login?

Junior Member Beiträge: 62 Beitrittsdatum: 11.11.08 Neueste Beiträge
I'm currently using Liferay 6.0.6.

I have the following properties in my portal-ext.properties file:
  • auth.login.url=/web/guest/login

Note, I do not set custom values for the default.landing.page.path, auth.forward.by.last.path, and auth.forward.by.redirect properties.

Here's what is currently happening:

  • A user who may have been previously browsing anonymously (as the guest user on my site) decides he wants to login to my site.
  • He clicks on the login link on the upper right hand corner of my site to login.
  • He is taken to a login page (that corresponds to the auth.login.url property above). The /web/guest/login page has been previously defined as a page under Manage > Pages - and the page is added as a hidden child page - i.e. it does not show up in the nav bar but one can still access it.
  • The user enters his login information and password and clicks on Sign-In
  • The user is logged in, but he is returned to the login page /web/guest/login


I need to know why the user is not getting returned to his last visited page - i.e. I do not want the user going back to /web/guest/login. I know this works (the redirect mechanism to last visited page) if I do not set a custom value for auth.login.url - i.e. I just the default login mechanism where the sign-in portlet is displayed in a maximized manner. However, I want to use a custom login page instead.

What am I doing wrong here or is this a limitation with Liferay? At the very least, I would like to redirect the user to the home page /web/guest/home. Is that possible?
thumbnail
Deb Troxel, geändert vor 13 Jahren.

RE: How does one redirect a user to his previous page after login? (Antwort)

Junior Member Beiträge: 81 Beitrittsdatum: 22.02.10 Neueste Beiträge
I had this exact situation. Maybe some experts here can suggest a better way, but what I did was change the theme to replace the sign in url to be my login page with the addition of a parameter that ensures that the sign-in page itself is not stored as the "last visited page".

I created a hidden sign-in page as you described.

In portal-ext.properties, I set
auth.login.url=/web/guest/sign-in

In portal_normal.vm I changed
    <a href="$sign_in_url" id="sign-in" rel="nofollow">$sign_in_text</a>

to
    <a href="/web/guest/sign-in?saveLastPath=0" id="sign-in" rel="nofollow">$sign_in_text</a>
lsli lsli, geändert vor 13 Jahren.

RE: How does one redirect a user to his previous page after login?

Junior Member Beiträge: 62 Beitrittsdatum: 11.11.08 Neueste Beiträge
Awesome! Thanks Deb, that worked for me. Yes, if anyone else has a different solution, please let me know. But this method certainlly works for me right now.
thumbnail
sachin mah, geändert vor 12 Jahren.

RE: How does one redirect a user to his previous page after login?

Junior Member Beiträge: 52 Beitrittsdatum: 04.12.10 Neueste Beiträge
Thanks Dev, me too is lookin for this solution...!!
Erik Lillegraven, geändert vor 10 Jahren.

RE: How does one redirect a user to his previous page after login?

Junior Member Beiträge: 27 Beitrittsdatum: 06.06.11 Neueste Beiträge
This did the trick for me:
In portal_normal.vm, get the current page and encode the url. Then add redirect parameter to sign-in url.
#set ($urlEncoder = $portal.getClass().forName("java.net.URLEncoder")) ##static class
#set ($currentPage = "$themeDisplay.getURLPortal()$themeDisplay.getURLCurrent()" )
#set ($myRedirect = $urlEncoder.encode("$currentPage", "UTF-8"))

<a href="$sign_in_url&amp;redirect=$myRedirect" id="sign-in" rel="nofollow">$sign_in_text</a>

After clicking the signIn link at the upper corner and then enter credentials, it will return to the current page.
thumbnail
Krzysztof Gołębiowski, geändert vor 10 Jahren.

RE: How does one redirect a user to his previous page after login?

Liferay Master Beiträge: 549 Beitrittsdatum: 25.06.11 Neueste Beiträge
Thanks Erik, this is a good solution. I'm just wondering why it has not been fixed since 2011 emoticon