FEU Redirect to last page after login [SOLVED]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
ESBertrand
Forum Members
Forum Members
Posts: 21
Joined: Tue Feb 02, 2010 5:02 am

FEU Redirect to last page after login [SOLVED]

Post by ESBertrand »

Hi everyone.  I have a 1.8.2 site with the latest FEU installed.  It's working great, though we have one issue that is really getting in the way of a good user experience.

On our site, we have a whole section that is protected and requires login.  We don't have the login form on all the pages since we don't want to figure it so prominently.  So upon clicking a link to any protected page (or being directed there from an email or other site), we have the normal code to redirect the user to login before they can see the protected content.  Here's the redirect code:

Code: Select all

    {if !$ccuser->loggedin() || ($ccuser->loggedin() && !$ccuser->memberof('Approved Members'))}
       {redirect_page page='member-login'}
    {/if}
The redirect_page tag works fine.  Once the user logs in, the FEU setting I have in place to redirect them to a specific page, works fine.  But in nearly every case, the user wants a different page than the one I have set up.

I've read a few posts related to this, but none have a definitive solution that would allow the redirect to bring them back to the page they originally wanted, post-login.  I've tried adding a "from" attribute to the redirect_page command, with and without the "redirect after login" FEU setting being set, but it just doesn't work.  I've also tried putting some code in to save the page alias so I could use it for the redirect after login setting, without success.

Would greatly appreciate any help with this; I'm an admitted newbie with PHP and Smarty (I'm much more comfortable in the .NET/C# world).  Thank you in advance!

Erik
Last edited by ESBertrand on Wed Nov 17, 2010 4:32 am, edited 1 time in total.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: FEU Redirect to last page after login

Post by jmcgin51 »

there is probably a more elegant way, but I think this would work:

on the protected page, use a UDT or Smarty to create a session variable to hold the HTTP_REFERER when the user arrives at that page (before he/she is immediately redirected).

after successful login, do one of two things: either call a UDT using an event, or redirect to a "redirect-after-login" page.  With either of these options (UDT would use PHP, redirect page would use Smarty), retrieve the session variable you created above, and redirect to it.

i.e. if you use the "redirect-after-login" page, it would be very simple and would look something like:
{redirect_page page=$smarty.session.referring_page}  This would redirect to the page that was originally requested, prior to the user being redirected to the first redirect page which took him to the login page...  make sense?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: FEU Redirect to last page after login

Post by calguy1000 »

1. On each protected page:

Code: Select all

{if !$ccuser->loggedin()}
   {session_put var='last_page' value=$page_alias}
   {redirect_page page='login'}
{/if}
2. Create a new gcb named return_last like this:

Code: Select all

{if isset($smarty.session.last_page)}
  {$smarty.session.last_page}
  {session_erase var='last_page'}
{/if}
3. In the FEU preferences:  "Page to Redirect to After Login" enter this:

Code: Select all

{global_content name='return_last'}
I may not have the syntax exactly correct,  I'm going from memory.  I have done this about 3 times already.

You will need the CGSimpleSmarty module.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
ESBertrand
Forum Members
Forum Members
Posts: 21
Joined: Tue Feb 02, 2010 5:02 am

Re: FEU Redirect to last page after login

Post by ESBertrand »

Thanks so much, CalGuy.  I set this up and it does seem to be saving the page alias through login, but when I click Login, the page is returned without stylesheets, and includes the error:

couldn't get pageid for
audio-video-protected

This tells me the page alias is remembered -- it is the alias of the protected page I originally requested -- but it looks like it cannot translate it into an ID.  I'll troubleshoot the error, but would welcome any input you might have on it, too.

Erik
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: FEU Redirect to last page after login

Post by jmcgin51 »

calguy1000 wrote: 1. On each protected page:

Code: Select all

{if !$ccuser->loggedin()}
   {session_put var='last_page' value=$page_alias}
   {redirect_page page='login'}
{/if}
2. Create a new gcb named return_last like this:

Code: Select all

{if isset($smarty.session.last_page)}
  {$smarty.session.last_page}
  {session_erase var='last_page'}
{/if}
3. In the FEU preferences:  "Page to Redirect to After Login" enter this:

Code: Select all

{global_content name='return_last'}
I may not have the syntax exactly correct,  I'm going from memory.  I have done this about 3 times already.

You will need the CGSimpleSmarty module.
...and there is the more elegant method I mentioned ;-)
ESBertrand
Forum Members
Forum Members
Posts: 21
Joined: Tue Feb 02, 2010 5:02 am

Re: FEU Redirect to last page after login

Post by ESBertrand »

I certainly didn't want to downplay your response, jmcgin51.  I kind of jumped on CalGuy's post since it had ready-made code to plug in.  It is basically what you suggested, in any case, except for the global content block part.  And, since I'm a PHP and Smarty novice, and I've already spent a couple of hours researching this, I wanted to give the code a try.

Thanks a bunch for taking the time to help out - I really appreciate it.

Erik
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: FEU Redirect to last page after login

Post by jmcgin51 »

no problem at all.  I just reread my last post and realized it probably didn't come across as I intended.  I was trying to quote Calguy and then say "THERE (Calguy's solution) is the more elegant solution that I said was probably out there somewhere".  Instead I made it look like I thought my solution was more elegant... :-[  oh well...  whatever works
ESBertrand
Forum Members
Forum Members
Posts: 21
Joined: Tue Feb 02, 2010 5:02 am

Re: FEU Redirect to last page after login

Post by ESBertrand »

One very happy guy here.  :D

I figured out what was causing the "Couldn't find pageid xxxx" error!

The global content block (GCB) needs to return only the alias of the original page, without any spaces or other markup before or after it.  Since I had pasted the global content block code in "design" mode, a few extra spaces and BR tags were included in the GCB's return value.  This was throwing off FEU, rightly so.

In the end, I found I had to remove all spaces, and even line breaks, from the code within the GCB.  So the final modified GCB code I have from CalGuy's suggestion is:

Code: Select all

{if isset($smarty.session.last_page)}{$smarty.session.last_page}{session_erase var='last_page'}{/if}
Simply put all the smarty commands on one line, with no spaces or hard returns between each.  With this in place, the redirects are now working flawlessly.  Thanks so, so much to CalGuy1000 and jmcgin51 for the help!

This should definitely be documented somewhere other than a lowly forum post, so others can benefit.

Erik
tonyg
Forum Members
Forum Members
Posts: 80
Joined: Sun Dec 14, 2008 4:54 am

Re: FEU Redirect to last page after login [SOLVED]

Post by tonyg »

hi,
sorry to be dense, but in step 3, you say
In the FEU preferences:  "Page to Redirect to After Login" enter this:
when I go to users&groups - Frontend User Management - Preferences....i don't see an option to 'redirect'...am I looking in the wrong spot?

thanks
tonyg
Forum Members
Forum Members
Posts: 80
Joined: Sun Dec 14, 2008 4:54 am

Re: FEU Redirect to last page after login [SOLVED]

Post by tonyg »

ok, i found it

it is in

users&groups - Frontend User Management - builtin authentication

thanks
jasnick
Power Poster
Power Poster
Posts: 695
Joined: Sat Jan 15, 2011 8:36 am
Location: Western Australia

Re: FEU Redirect to last page after login [SOLVED]

Post by jasnick »

Finally arrived at this post after much searching - solution works perfectly!

Thanks to all!
fireboydesign
Forum Members
Forum Members
Posts: 17
Joined: Sun Sep 20, 2009 10:42 pm
Location: Portsmouth, UK

Re: FEU Redirect to last page after login [SOLVED]

Post by fireboydesign »

Hi all

Just wondering if this is possible...

Calguy's code above works great, but what I need is to be able to redirect to a news detail page, which isn't possible because the FEU module only accepts page ID/alias for post-login redirect.

Has anyone ever found a solution or method for doing this? Since FEU only allows you to use a page ID or alias it leaves you a bit stuck if you wanted to redirect to a dynamic page such as news/blog detail page.

Any advice much appreciated!

Steve
Post Reply

Return to “Modules/Add-Ons”