2013-06-27 35 views
0

我面臨問題,我不知道如何在我的自定義模塊控制器中使用登錄功能,而無需粘貼整個登錄代碼。我想通過我的控制器登錄功能,登錄功能返回會話/結果。登錄函數在magento中的自定義模塊控制器中使用

請任何1我可以出去。

我有1.4.2版本的magento。

+0

請告訴我們你已經嘗試過嗎? –

+0

Ani不明白你想問什麼? –

+0

你想做什麼:?無論你是想要寫過默認登錄,還是想停止默認登錄,並讓你的自定義登錄去做東西 –

回答

2

你有什麼試過?你看過標準的magento控制器(Mage_Customer_AccountController::loginPostAction)嗎?它不是代碼的那麼多線..

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

和的try ... catch +消息/錯誤處理

+0

謝謝,但如何從會話中獲取錯誤? –

+0

見https://makandracards.com/magento/10723-messages-and-global-messages-blocks –

0

請看應用程序/代碼/核心/法師/客戶/控制器/ 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 
} 
相關問題