Magento重定向到登录页面,而用户没有登陆登陆

问题描述 投票:3回答:3

我希望在登陆时将用户重定向到登录页面,而用户尚未登录。

例如 :-

example.com ->(not logged in)-> redirect to login page.

example.com ->(logged in)-> redirect to Home page.

我怎样才能做到这一点 ?

我被发现有这样的功能

public function preDispatch()
{
    parent::preDispatch();

    if (!Mage::getSingleton('customer/session')->authenticate($this)) {
        $this->setFlag('', 'no-dispatch', true);
    }
}

我如何使用或在哪里使用它。

希望有些人会有这方面的经验。 提前致谢

magento magento-1.5
3个回答
18
投票

这个省钱就是我,

if(!$this->helper('customer')->isLoggedIn()){

  Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));

}

我在cms页面块中调用它。希望对某人有所帮助。


2
投票
$customerId = (int) $this->getRequest()->getParam('id');
$customer   = Mage::getModel('customer/customer')
                  ->load($customerId);

$userSession = Mage::getSingleton('customer/session');
$userSession->setCustomer($customer);
Mage::dispatchEvent('customer_login', array('customer'=>$customer));

$this->getResponse()->setRedirect(Mage::getUrl('customer/account'));

希望这有帮助


1
投票
$redirect_url = Mage::getUrl('customer/account/login/');
$current_url = Mage::helper('core/url')->getCurrentUrl();
if((!$this->helper('customer')->isLoggedIn()) && ($current_url != $redirect_url)){
    Mage::app()->getFrontController()->getResponse()->setRedirect($redirect_url);
}
© www.soinside.com 2019 - 2024. All rights reserved.