duanjian4331 2014-03-18 16:43
浏览 51
已采纳

Magento客户以编程方式登录

I have the code:

function loginUser( $email, $password )
{
    /** @var $session Mage_Customer_Model_Session */
    $session = Mage::getSingleton( 'customer/session' );

    try
    {
        $session->login( $email, $password );
        $session->setCustomerAsLoggedIn( $session->getCustomer() );
        return 1;
    }
    catch( Exception $e )
    {
        return $e;
    }
}

$test = loginUser("login","password");
echo "test";
print_r($test);
die;

but I always get

Mage_Core_Exception Object ( [_messages:protected] => Array ( ) [message:protected] => Invalid login or password.

Login and password is correct, I tried many accounts, with the same result.

How can I log in correctly?

  • 写回答

2条回答 默认 最新

  • douba8758 2014-03-19 05:34
    关注
    <?php
    function loginUser( $email, $password )
        require_once ("app/Mage.php");
        umask(0);
        ob_start();
        session_start();
        Mage::app('default');
        Mage::getSingleton("core/session", array("name" => "frontend"));
    
        $websiteId = Mage::app()->getWebsite()->getId();
        $store = Mage::app()->getStore();
        $customer = Mage::getModel("customer/customer");
        $customer->website_id = $websiteId;
        $customer->setStore($store);
        try {
            $customer->loadByEmail($email);
            $session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
            $session->login($email, $password);
        }catch(Exception $e){
    
        }
    
    
      } 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?