Jump to content

How to redirect to original page after user login


Visiedo

Recommended Posts

Hi,

I was looking for a way to redirect a user to the original page after the login, avoiding the default behavior from prestashop, i.e. redirect to the "my-account" page.

 

There are several threads on the topic, but at the end I could not find anything that fulfilled my reqs. and finally come with this method. I would like to get your opinions, specially if you believe it won't work under some circumstances, since it is still not fully verified.

 

My [simple] requirements:

  • Redirect a user to the original page after signing in, when using the login link at the "blockuserinfo". No exceptions in any page
  • Should work for both HTTP and HTTPS

The solution:

 

Edit the "blockuserinfo.tpl", and change this part at the end of the file (lines 56-60 in 1.5.3)

 

{if $logged}
  <a href="{$link->getPageLink('my-account', true)}" class="account"><span>{$cookie->customer_firstname} {$cookie->customer_lastname}</span></a>
  <a href="{$link->getPageLink('index', true, NULL, "mylogout")}" title="{l s='Log me out' mod='blockuserinfo'}" class="logout">{l s='Log out' mod='blockuserinfo'}</a>
 {else}
  <a href="{$link->getPageLink('my-account', true)}" class="login">{l s='Log in / Join us!' mod='blockuserinfo'}</a>

 {/if}

by
{if $logged}
  <a href="{$link->getPageLink('my-account', true)}" class="account"><span>{$cookie->customer_firstname} {$cookie->customer_lastname}</span></a>
  <a href="{$link->getPageLink('index', true, NULL, "mylogout")}" title="{l s='Log me out' mod='blockuserinfo'}" class="logout">{l s='Log out' mod='blockuserinfo'}</a>
 {else}
 <a href="{$link->getPageLink('authentication', true)}?back={if $smarty.server.SERVER_PROTOCOL|strstr:"https"}https://{else}http://{/if}{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}" class="login">{l s='Log in / Join us!' mod='blockuserinfo'}</a>

 {/if}

 

I replace the call to 'my-account' by a direct call to the 'authentication' controller, including the full URL of the current page in the "back" parameter.

It is important to include also the protocol "http:// or
otherwise the it will assume that the value for "back" is the name of a controller, and will result in a redirection to:
index.php?controler='your URL'

 

returning a 404.

 

I am very interested on your opinions, I hope you find it correct and useful ;-)

 

Please also feel free to suggest improvements
Edited by Visiedo (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 1 year later...
  • 5 months later...
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...