All about Magento E-commerce Store.......MagentoForum: Magento: Redirect Customer to Login page if not logged in

Tuesday, October 11, 2011

Magento: Redirect Customer to Login page if not logged in



If you are developing a module which needs to give access
to its content only to logged in user then the preDispatch function will be very useful.
This dispatches event before action.
Just write the following function in your module's controller and customer
 log in is checked before each of your controller action.

/**  * Checking if user is logged in or not  
* If not logged in then redirect to customer login 
*/ public function preDispatch() {  
parent::preDispatch();   
if (!Mage::getSingleton('customer/session')->authenticate($this)) {  
$this->setFlag('', 'no-dispatch', true);  } } 
Hope this helps. Thanks.


No comments:

Post a Comment