Вход пользователя Magento программно

У меня есть код:

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; 

но я всегда получаю

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

Логин и пароль верны, я попробовал много учетных записей с таким же результатом.

Как я могу войти в систему правильно?

 <?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){ } } ?> по <?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){ } } ?> на <?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){ } } ?> на <?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){ } } ?> 

Мартин, пожалуйста, попробуйте под кодом …

  require_once "app/Mage.php"; Mage::app('default'); umask(0); Mage::getSingleton('core/session', array('name' => 'frontend')); $session = Mage::getSingleton('customer/session'); $session->start(); if (!empty($email) && !empty($password )) { try { $session->login($email, $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($email); $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($email); } catch (Exception $e) { // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password } } else { $session->addError('Login and password are required.'); } по  require_once "app/Mage.php"; Mage::app('default'); umask(0); Mage::getSingleton('core/session', array('name' => 'frontend')); $session = Mage::getSingleton('customer/session'); $session->start(); if (!empty($email) && !empty($password )) { try { $session->login($email, $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($email); $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($email); } catch (Exception $e) { // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password } } else { $session->addError('Login and password are required.'); } 

Вход

 try{ $customer = Mage::getModel("customer/customer"); $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); $customer->loadByEmail($email); //load customer by email i /* if customer has ,then login */ if($customer->getId()>0){ $userSession = Mage::getSingleton('customer/session'); $userSession->setCustomer($customer); Mage::dispatchEvent('customer_login', array('customer'=>$customer)); }else{ echo "Error"; } }catch(Exception $e) { print_r($e->getMessage()); } на try{ $customer = Mage::getModel("customer/customer"); $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); $customer->loadByEmail($email); //load customer by email i /* if customer has ,then login */ if($customer->getId()>0){ $userSession = Mage::getSingleton('customer/session'); $userSession->setCustomer($customer); Mage::dispatchEvent('customer_login', array('customer'=>$customer)); }else{ echo "Error"; } }catch(Exception $e) { print_r($e->getMessage()); } на try{ $customer = Mage::getModel("customer/customer"); $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); $customer->loadByEmail($email); //load customer by email i /* if customer has ,then login */ if($customer->getId()>0){ $userSession = Mage::getSingleton('customer/session'); $userSession->setCustomer($customer); Mage::dispatchEvent('customer_login', array('customer'=>$customer)); }else{ echo "Error"; } }catch(Exception $e) { print_r($e->getMessage()); } на try{ $customer = Mage::getModel("customer/customer"); $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); $customer->loadByEmail($email); //load customer by email i /* if customer has ,then login */ if($customer->getId()>0){ $userSession = Mage::getSingleton('customer/session'); $userSession->setCustomer($customer); Mage::dispatchEvent('customer_login', array('customer'=>$customer)); }else{ echo "Error"; } }catch(Exception $e) { print_r($e->getMessage()); }