Magento перенаправить на страницу входа, пока пользователь не авторизуется при посадке - PullRequest
3 голосов
/ 07 января 2012

Я хочу перенаправить пользователя на страницу входа при посадке, пока пользователь не вошел в систему.

например: -

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);
    }
}

Как я могу использовать это или где я должен это использовать.

Надеюсь, у некоторых будет опыт по этому вопросу.Заранее спасибо

Ответы [ 3 ]

18 голосов
/ 10 января 2012

Это спаси меня,

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

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

}

И я позвонил в cms page block. Надеюсь, это кому-нибудь поможет.

2 голосов
/ 07 января 2012
$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 голос
/ 09 апреля 2015
$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);
}
...