Login API Magento
<?php
error_reporting(0);
$email = $_POST['email'];
$password = $_POST['password'];
if(empty($email) || empty($password))
{
$return_array['status']= "2";
$return_array['message']= "please provide required parameter";
echo json_encode($return_array);
exit;
}
include("../app/Mage.php"); //Call mage file
umask(0);
Mage::app();
try
{
$customer=Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->authenticate($email, $password);
//If the exception is thrown, this text will not be shown
$customer1=Mage::getModel('customer/customer');
$customer1->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer1->loadByEmail($email); //load customer by email id
$return_array = $customer1->getData(); // Fetch user detail
$return_array1 = $customer1->getId(); //Fetch user id
$customer_detail = array("status"=>"1","message"=>"success","Customer_id"=>$return_array1,"user_profile"=>$return_array,);
echo json_encode($customer_detail);
exit;
}
//catch exception
catch(Exception $e) {
$return_array['status'] = "0";
$return_array['message'] = $e->getMessage(); //Get a failed response.
echo json_encode($return_array);
exit;
}
?>
No comments: