Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android magento customer login(authentication) using using SOAP API

i facing problem while i try to login(authentication) magento customer. i cant find proper way for login customer using there email and password. so, can u suggest me that how can i make authentication or login customer in magento store using SOAP API. i tried this code as given bellow

env.dotNet = false;
            env.xsd = SoapSerializationEnvelope.XSD;
            env.enc = SoapSerializationEnvelope.ENC;

            SoapObject request = new SoapObject(NAMESPACE, "login");

            request.addProperty("username", "xyz");
            request.addProperty("apiKey", "xyz");

            env.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.debug = true;
            androidHttpTransport.call("", env);
            Object result = env.getResponse();

            Log.d("sessionId", result.toString());

            // making call to get list of customers

            String sessionId = result.toString();
            request = new SoapObject(NAMESPACE, "customerCustomerInfo");
            request.addProperty("sessionId", sessionId);
            request.addProperty("customerId", "2032");
            request.addProperty("email", "[email protected]");
            request.addProperty("password", "password");


            env.setOutputSoapObject(request);
            androidHttpTransport.call(SOAP_ACTION, env);
            androidHttpTransport.debug = true;
            result = env.getResponse();

            Log.d("Customer List", result.toString());

}

but it does not help me so is there any one who's have solution of my question.

Thank you....

like image 317
Sameer Donga Avatar asked Jul 31 '14 09:07

Sameer Donga


2 Answers

There is no direct option for login the customer to magento.The password you retrieve from API is hash_password and you cant check the equality of password. But you can use the method explained below to login into magento.

  1. Create an external php file and access the magento login there

    require_once('../magentosite/app/Mage.php'); //Path to Magento umask(0); Mage::app();

    $id = 1;

    try{ $result = Mage::getModel('customer/customer')->setWebsiteId($id)->authenticate($email, $password); }catch( Exception $e ){ $result = false; }

  2. Send the username and password from android to that php page using JSON,and get the "result".

  3. if the result is "true" the username and password exist in the DB.

like image 136
Remees M Syde Avatar answered Nov 05 '22 22:11

Remees M Syde


Actually you can check/login user using SOAP, you just need to extend it a little bit. At app/code/core/Mage/Customer/Model/Customer/Api.php add new function

public function login($email, $password){
        /** @var $session Mage_Customer_Model_Session */
        $session = Mage::getSingleton( 'customer/session' );
        Mage::app()->getStore()->setWebsiteId(1);
        try
        {
            $session->login( $email, $password );
            $customer = $session->getCustomer();

            return json_encode(array('status' => 'OK', 'userData' => $this->info($customer->getId())));
        }
        catch( Exception $e )
        {
            return json_encode(array('status' => 'error', 'message' => $e->getMessage()));
        }
    }

At app/code/core/Mage/Customer/etc/api.xml

<config>
<api>
    <resources>
        <customer translate="title" module="customer">
         <methods>
        ...
               <login translate="title" module="customer">
                    <title>Login customer</title>
                    <acl>customer/login</acl>
                </login>

also at the end

        <acl>
        <resources>
            <customer translate="title" module="customer">
            ...
            <login translate="title" module="customer">
                    <title>Login</title>
            </login>

And here you can test yout login function

<?php
$host = "http://youmagentohost/index.php";
$client = new SoapClient($host."/api/soap/?wsdl"); //soap handle
$apiuser= "apiuser"; //webservice user login
$apikey = "apikey"; //webservice user pass
$action = "customer.login";
try {

    $sess_id= $client->login($apiuser, $apikey);
    $params = array('email'=>'[email protected]', 'password'=>'password');

    print_r($client->call($sess_id, $action, $params));
}
catch (Exception $e) { //while an error has occured
    echo "==> Error: ".$e->getMessage();
    exit();
}
?>

Its not nice solution but its better than nothing. Don't forget to rewrite all core files ;)

like image 45
Kipras Avatar answered Nov 05 '22 21:11

Kipras