登录功能用于magento中的自定义模块控制器

时间:2013-06-27 09:52:28

标签: magento magento-1.4

我遇到问题,我不知道如何在我的自定义模块控制器中使用登录功能而不粘贴整个登录代码。我想通过我的控制器点击登录功能,登录功能返回会话/结果。

请任何一个人能帮我。

我有1.4.2版本的magento。

2 个答案:

答案 0 :(得分:2)

你有什么尝试?您是否看过标准的magento控制器(Mage_Customer_AccountController::loginPostAction)?它不是那么多代码......

$session = Mage::getSingleton('customer/session');
$session->login($username, $password);

并尝试...捕获+消息/错误处理

答案 1 :(得分:0)

请查看app / code / core / Mage / Customer / controllers / AccountController.php和公共函数loginPostAction(),你会清楚地了解magento如何处理异常

$session = Mage::getSingleton('customer/session');
 try {
    $session->login($username, $password);
    if ($session->getCustomer()->getIsJustConfirmed()) {
       $this->_welcomeCustomer($session->getCustomer(), true);
    }
} catch (Mage_Core_Exception $e) {
    switch ($e->getCode()) {
    case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
        $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
        $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
        break;
    case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
        $message = $e->getMessage();
        break;
    default:
        $message = $e->getMessage();
    }
    $session->addError($message);
    $session->setUsername($login['username']);
} catch (Exception $e) {
    // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
}