2011-06-27 65 views
0

我正在研究magento的ajax登錄,並且在處理ssl時遇到了一個小問題。Magento Ajax登錄 - 通過SSL

我用來顯示我的登錄視圖的請求頁面是一個不安全的頁面。在此頁面中,我使用ajax發佈到安全網址(https://client.devserver/customer/account/ajaxLoginPost/)。我回來的json響應是正確的,但是當我刷新頁面時,用戶未登錄。

我已經在非安全站點上測試了此功能,並且按預期工作。當我添加下一層SSL時,它似乎只會中斷。

任何幫助,這是非常感謝。

這裏是我的控制器的代碼。

public function ajaxLoginPostAction() 
{ 
    if ($this->_getSession()->isLoggedIn()) { 
     $this->_redirect('*/*/'); 
     return; 
    } 
    $session = $this->_getSession(); 

    if ($this->getRequest()->isPost()) { 
     $login = $this->getRequest()->getPost('login'); 
     if (!empty($login['username']) && !empty($login['password'])) { 
      try { 
       $session->login($login['username'], $login['password']); 
       if ($session->getCustomer()->getIsJustConfirmed()) { 
        $this->_welcomeCustomer($session->getCustomer(), true); 
       } 
       $messages = array("isAuthed" => true); 
      } catch (Mage_Core_Exception $e) { 
       switch ($e->getCode()) { 
        case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD: 
         $message = $e->getMessage(); 
         break; 
        default: 
         $message = $e->getMessage(); 
       } 
       $messages = array("isAuthed" => false, "userName" => $login['username'],"error"=> $message); 
      } catch (Exception $e) { 
       // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password 
      } 

     } else { 
      $messages = array("isAuthed" => false, "userName" => $login['username'],"error"=>'Login and password are required.'); 
     } 
    } 
    //$this->_loginPostRedirect(); 
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($messages)); 
} 
+0

我不明白這可以「工作」,因爲您的AJAX請求是明文的,即易於閱讀且不安全。這是您嘗試保護的用戶/密碼,而不是會話數據。 –

回答

3

實際上有兩個cookie(因此有兩個會話),一個用於「http」連接,一個用於「https」。

您可以在執行登錄後轉發到安全頁面 - 這不需要AJAX表單 - 或者在JSON響應中返回SID,並找到使用該值設置非安全cookie的方法。

第三種選擇是將整個網站保留爲安全,這是額外的工作&服務器的成本,所以並非所有的企業都願意採取這種合理的預防措施。