cancel
Showing results for 
Search instead for 
Did you mean: 

Conditional redirect after login

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Conditional redirect after login

I have built an external application that sits beside my Magento install. I use cURL to get the currently logged-in Magento user with the Magento REST API, and use that ID to authenticate my external application. My external application has a link to the Magento login page if the user is not logged in and a link to the logout page if they are logged in. 

 

I want to redirect the user back to this application if that is where they clicked the login/logout link from. I'd rather not build a complex module, rather I want to extend the basic Magento login controller to look for a $_GET variable that was attached to the URL, and if it is there, redirect the user to the external application. 

 

Like maybe my login link is like this:

http://mysite.com/shop/customer/account/login/?p=external

and the controller sees that $_GET['external'] is not empty, so it redirects to 

http://mysite.com/external

or if it is empty, redirect as usual to the dashboard. 

 

I have found a small tutorial that says to extend Magento\Customer\Controller\Account\LoginPost

but where do I extend it?

Do I put it in /app/code/Magento/Customer?

1 REPLY 1

Re: Conditional redirect after login

Try the below code for redirection

 

if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() )
{                  
    $this->_redirect('http://mysite.com/shop/customer/account/login/?p=external'); }