0

我正在尝试创建自己的登录页面,该页面在花式弹出窗口中使用 Ajax。我创建了自己的模块来扩展默认客户 AccountController。它似乎工作正常,但是当用户成功登录时,控制器将客户数据保存在会话中,但是当我返回主页时,客户会话数据不再存在。我需要在返回时设置会话吗?

我的控制器在下面

    public function loginPostAction()
{


   $session = Mage::getSingleton('customer/session');

    if ($this->getRequest()->isPost()) {
        $login = $this->getRequest()->getPost('login');

         Mage::log($login['username'].$login['password']);
        if (!empty($login['username']) && !empty($login['password'])) {

            try {
                $session->login($login['username'], $login['password']);
               // Mage::log($session->login($login['username'], $login['password']));
                $this->_welcomeCustomer($session->getCustomer(), true);
                if ($session->getCustomer()->getIsJustConfirmed()) {
                    $this->_welcomeCustomer($session->getCustomer(), true);
                    $response =  "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']);
                        Mage::log("EXCEPTION_EMAIL_NOT_CONFIRMED");
                        $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                        $response = "This account is not confirmed";
                        break;
                    case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                        $message = $e->getMessage();
                        $response = "Invalid email or password";
                        Mage::log("EXCEPTION_INVALID_EMAIL_OR_PASSWORD");
                        break;
                    default:
                        $message = $e->getMessage();
                         Mage::log("EXCEPTION_default");
                }
                //$session->addError($message);
                Mage::log("about setting the username");
                $session->setUsername($login['username']);
            } catch (Exception $e) {
                // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
            }
        } else {
            Mage::log("in the else");
            $session->addError($this->__('Login and password are required.'));
            $response = 'Login and password are required.';
        }
    }
    Mage::log($session->getCustomer());

    //echo $response;
    //$this->_loginPostRedirect();
}

任何帮助将不胜感激

通过更新 config.xml 文件修复。我没有覆盖客户控制器

<router>
    <customer>
            <args>
                <modules>
                    <companyname_loginform before="Mage_Customer">companyname_Loginform</companyname_loginform>
                </modules>
            </args>
        </customer>

4

2 回答 2

0

如果有人还需要magento ajax登录功能,我可以推荐我们公司开发的magento插件。这是链接 - https://store.plumrocket.com/magento-extensions/popup-login-magento-extension.html

我们也有文档和论坛。随时问我们任何问题。

谢谢!

于 2013-08-29T22:50:44.850 回答
-1

我发现了这个问题。我只是扩展客户帐户控制器 - 我没有从 config.xml 正确覆盖它

于 2012-10-04T18:47:17.863 回答