TheLousyCoder Posted January 19, 2015 Share Posted January 19, 2015 Hi, I am writing APIs for mobile app. I am stuck at the point how to authenticate users for mobile app with prestashop web services or API. Please help me, it's urgent Link to comment Share on other sites More sharing options...
Nikhil.nj Posted March 26, 2015 Share Posted March 26, 2015 ME too, I think we must create one file to handle the request and the response but how??? Link to comment Share on other sites More sharing options...
TheLousyCoder Posted March 26, 2015 Author Share Posted March 26, 2015 Hi Nikhil, I somehow made a function that will authenticate a user, I asked my Java developer to store and maintain the userid that I pass after successful authentication. Below function that I write might help you. public function authenticate($email, $passwd) { $errors = array(); $ct = array(); Hook::exec('actionBeforeAuthentication'); //echo 'hook exe'; $passwd = trim($passwd); $email = trim($email); if (empty($email)) { $errors[] = 'An email address required.'; } elseif (!Validate::isEmail($email)) { $errors[] = 'Invalid email address.'; } elseif (empty($passwd)) { $errors[] = 'Password is required.'; } elseif (!Validate::isPasswd($passwd)) { $errors[] = 'Invalid password.'; } else { $customer = new Customer(); $context = Context::getContext(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (!$authentication || !$customer->id) { $errors = Tools::displayError('Email/Password is wrong.'); } else { $context->cookie->id_compare = isset($context->cookie->id_compare) ? $context->cookie->id_compare : CompareProduct::getIdCompareByIdCustomer($customer->id); $context->cookie->id_customer = (int) ($customer->id); $context->cookie->customer_lastname = $customer->lastname; $context->cookie->customer_firstname = $customer->firstname; $context->cookie->logged = 1; $customer->logged = 1; $context->cookie->is_guest = $customer->isGuest(); $context->cookie->passwd = $customer->passwd; $context->cookie->email = $customer->email; // Add customer to the context $context->customer = $customer; if (Configuration::get('PS_CART_FOLLOWING') && (empty($context->cookie->id_cart) || Cart::getNbProducts($context->cookie->id_cart) == 0) && $id_cart = (int) Cart::lastNoneOrderedCart($context->customer->id)) { $context->cart = new Cart($id_cart); } else { $context->cart->id_carrier = 0; $context->cart->setDeliveryOption(null); $context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int) ($customer->id)); $context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int) ($customer->id)); } $context->cart->id_customer = (int) $customer->id; $context->cart->secure_key = $customer->secure_key; $context->cart->save(); $context->cookie->id_cart = (int) $context->cart->id; $context->cookie->write(); $context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); $ct['cart'] = (array) get_object_vars($context->cart); $ct['customer'] = (array) get_object_vars($context->customer); $ct['cookie'] = (array) get_object_vars($context->cookie); // print_r($ct); $token = Tools::getToken(false); } } if (count($errors) > 0) { $fjson = json_encode($errors, true); } else { $fjson = json_encode($ct, true); } $res = '{' . '"status":200,' . '"datajson":' . $fjson . '}'; return $res; } Link to comment Share on other sites More sharing options...
Nikhil.nj Posted March 26, 2015 Share Posted March 26, 2015 Yep after searching I got something on same topic so thanks for reply. In which language you developed your API for Mobile Development? If you using PHP then would you like to help me to build better and guide the actual flow for the API ?? Thanks once again. Nick ['} Link to comment Share on other sites More sharing options...
TheLousyCoder Posted March 26, 2015 Author Share Posted March 26, 2015 I am developing API in PHP only. I will be glad to help if you need something. Link to comment Share on other sites More sharing options...
Nikhil.nj Posted March 26, 2015 Share Posted March 26, 2015 (edited) Nice then, Its my pleasure to share with you You said you developing in php but I want to know that you create web services in default directory like -ROOT/webservices or you create your own -ROOT/MyWebServices/api if you used default then you change or modify the dispatcher.php file Edited March 26, 2015 by Nikhil.nj (see edit history) Link to comment Share on other sites More sharing options...
Nikhil.nj Posted March 26, 2015 Share Posted March 26, 2015 Hiii Lousy, Glad to talk you once again, I want to know how the api called in prestashop's web services. and how the function called which you gave me for authenticate the customer ???? Thanks in Advance. Nick ['} Link to comment Share on other sites More sharing options...
Nikhil.nj Posted March 27, 2015 Share Posted March 27, 2015 Hello dear, Hope you well and fine. I am using library Prestashop's web services and it gives only XML and I want only JSON output.. Is it possible to get JSON code using this library if YES then how?? Thanks in Advance Nikhil ['} Link to comment Share on other sites More sharing options...
arjit Posted June 25, 2015 Share Posted June 25, 2015 Hi, I am also stuck at the same problem. with username and password how can I authenticate the user ? Link to comment Share on other sites More sharing options...
VinayC Posted September 18, 2015 Share Posted September 18, 2015 Hi, Need a help to create signup and login API using PHP. I'm not aware of where to start. Any help would be really great. Thanks & Regards, VinayC Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now