Tuesday, November 20, 2012

Authenticating Customer Outside Magento

<?php
/**
* Magento validation starts here
*/
require_once (dirname(dirname(realpath(__FILE__))).'/app/Mage.php');
umask(0);
Mage::app();
//Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session');
try{
$session->login($_REQUEST['login']['username'],$_REQUEST['login']['password']);
$session->setCustomerAsLoggedIn($session->getCustomer());
//Load the customer modules
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
//Get customer attribbutes
$customer->loadByEmail($_REQUEST['login']['username']);
/**
* Do the stuff you need to when user authenticates
*/
}catch (Exception $e){
$key ="authenticate=N";
}

No comments: