Magento News

 

Magento – Require Login

I have the following controller action, which redirects to the login page if no user is logged in:

public function requireloginAction() {
  if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
    // Not logged in
    // Save requested URL for later redirection
    Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());
    header("Status: 301");
    header('Location: '.Mage::helper('customer')->getLoginUrl());  // send to the login page
  }
  else {
    // Logged in
    .. do something ..
  }
}

By using setBeforeAuthUrl, once the user logs in he/she is redirected back to this action.

Problem:

If instead of logging in, the user, creates an account he/she is then redirected to the main page, rather then to the url set in setBeforeAuthUrl.

Question:

Is there something similar to setBeforeAuthUrl that works with Account Creation too? Or how can I achieve the desired effect?

(Magento Version 1.6)

Magento – Require Login

Possibly Related Posts:


 

Leave a Reply