0

ログインのコード全体を貼り付けずに、カスタム モジュール コントローラーでログイン機能を使用する方法がわかりません。コントローラーを介してログイン機能を実行すると、ログイン機能がセッション/結果を返します。

どれか1つください。

私はmagentoの1.4.2バージョンを持っています。

4

2 に答える 2

2

何を試しましたか?標準の magento コントローラー ( Mage_Customer_AccountController::loginPostAction) をご覧になりましたか? それはそれほど多くのコード行ではありません..

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

そして試してみてください...キャッチ+メッセージ/エラー処理

于 2013-06-27T09:59:24.780 に答える
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
}
于 2013-06-27T11:37:06.320 に答える