Page 1 of 1

FEU Redirect to last page after login [SOLVED]

Posted: Tue Nov 16, 2010 2:53 am
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

Re: FEU Redirect to last page after login

Posted: Tue Nov 16, 2010 3:47 am
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?

Re: FEU Redirect to last page after login

Posted: Tue Nov 16, 2010 5:12 am
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.

Re: FEU Redirect to last page after login

Posted: Tue Nov 16, 2010 1:18 pm
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

Re: FEU Redirect to last page after login

Posted: Tue Nov 16, 2010 1:43 pm
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 ;-)

Re: FEU Redirect to last page after login

Posted: Tue Nov 16, 2010 2:45 pm
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

Re: FEU Redirect to last page after login

Posted: Tue Nov 16, 2010 3:03 pm
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

Re: FEU Redirect to last page after login

Posted: Wed Nov 17, 2010 4:31 am
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

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

Posted: Wed Nov 17, 2010 3:27 pm
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

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

Posted: Wed Nov 17, 2010 3:46 pm
by tonyg
ok, i found it

it is in

users&groups - Frontend User Management - builtin authentication

thanks

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

Posted: Sat Jan 07, 2012 11:15 pm
by jasnick
Finally arrived at this post after much searching - solution works perfectly!

Thanks to all!

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

Posted: Mon Jul 23, 2012 10:44 am
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