drwkqwa82140 2014-10-30 13:19 采纳率: 0%
浏览 55

Magento登录_forward方法失败

I am trying to get Magento to log me in through a form I built by using the _forward() method used to pass info to the proper controller. However, this is not working. I can't tell if the correct data is getting passed to the controller. By logging my variables, I can see that the data is there (username, hashed password, if the account actually exists, etc.). By the Magento documentation, I am calling the method properly, with the correct parameters.

Is there a step I am missing?

Here is my code and how it works:

function customerLogin()
{
    var email    = jQuery('#login-email').val();
    var password = jQuery('#login-password').val();
    jQuery.post("orderkickoff/login/login", { 'login[username]': email, 'login[password]': password } );
}

This is jQuery on the front end that gets the email and the password and then posts that information to MY controller. By setting break points, I can see that my controller is getting called properly, and the data is there.

class Namespace_OrderKickoff_LoginController extends Mage_Core_Controller_Front_Action {

public function loginAction()
{
    //if customer is not logged in
    if(!Mage::getSingleton('customer/session')->isLoggedIn())
    {

        // get the email and load the customer by id
        $login = $this->getRequest()->getPost('login');
        $email = $login['username'];
        $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($email);
        $quote = Mage::getSingleton('checkout/cart')->getQuote();

        //If the customer exists, log them in by forwarding to loginPost
        if($customer->getId())
        {
            // just make the customer log in
            $mysession = Mage::getSingleton('customer/session');
            $mysession->setBeforeAuthUrl(Mage::getUrl('customer/account/index'));
            $mysession->setAfterAuthUrl(Mage::getUrl('customer/account/index'));
            $this->_forward('loginPost','account','customer');
        }
        else
        {
            Mage::log("There is no customer with that email");
        }
    }

    $this->_redirect('customer/account/index');
    return;
}

}

This is my controller that you can see gets the customers session, and then attempts to forward the data to the controller AccountController and call the loginPost function in order to log the user in.

This is where the process is failing. I step through everything and return to my function, but nothing happens. There is no redirect, the page just stays there. I can't figure out why this is not logging me in and then redirecting me.

Can anyone tell me what I am doing wrong?

Let me know if you need any more information.

Thanks!

  • 写回答

1条回答 默认 最新

  • duanjunao9348 2014-10-30 14:41
    关注

    you need to change you logic for login.

    public function loginAction(){
        if(!Mage::getSingleton('customer/session')->isLoggedIn())
        {
            $login = $this->getRequest()->getPost('login');
            $email = $login['username'];
            $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($email);
            if($customer->getId())
            {
                    $websiteId = Mage::app()->getWebsite()->getId();
                $store = Mage::app()->getStore();
                $customer = Mage::getModel("customer/customer");
                $customer->website_id = $websiteId;
                $customer->setStore($store);
                $customer->loadByEmail($email);
                Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
            }
            else
            {
                Mage::log("There is no customer with that email");
            }
        }
    
        $this->_redirect('customer/account/index');
        return;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能