TheLousyCoder Posted January 19, 2015 Share Posted January 19, 2015 Hi, I am developing APIs to be used for Mobile app we are currently developing. I am stuck in the issue of how the authentication Link to comment Share on other sites More sharing options...
NemoPS Posted January 19, 2015 Share Posted January 19, 2015 Quite honestly I'd create a separately accessible api (that's what I did for the app i'm currently working on), since the default one sucks a bit. In any case for the default, you need to send http authentication headers (depends on your app's language of course) Link to comment Share on other sites More sharing options...
TheLousyCoder Posted January 19, 2015 Author Share Posted January 19, 2015 Thanks Nemo for reply. I am already working the same way as you suggested. Currently developing Android app using Java. But, I am not sure how would I go for authentication , I have created restful APIs for products and categories but this is freaking me out. Can you please help me in this regard, Any logic or code will be pretty helpful. Link to comment Share on other sites More sharing options...
NemoPS Posted January 19, 2015 Share Posted January 19, 2015 Well I don't know how to help you with java, I don't know it I am doing it in C# for windows phone Link to comment Share on other sites More sharing options...
TheLousyCoder Posted January 19, 2015 Author Share Posted January 19, 2015 I am basically at server side, writing code in PHP for authentication. If you can help me with that Link to comment Share on other sites More sharing options...
NemoPS Posted January 19, 2015 Share Posted January 19, 2015 Uhm, you mean you need to create an auth system? Well i'm not a pro with security, I'd go got a $_GET and check something like a security hash and username, something like that Link to comment Share on other sites More sharing options...
TheLousyCoder Posted January 19, 2015 Author Share Posted January 19, 2015 I think you are getting me wrong, I have prestashop 1.5.6, on that I am writing API script for mobile app. I have included init.php in my code and trying to authenticate the user. I tried code written in Authcontroller but not able to get the user context. Link to comment Share on other sites More sharing options...
TheLousyCoder Posted January 19, 2015 Author Share Posted January 19, 2015 For more info, Here is the code I am trying to get working. public function checkuser($email, $passwd) { $error = 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 { $contaxt = Context::getContext(); $customer = new Customer(); $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(); print_r($context); die; Hook::exec('actionAuthentication'); //echo 'haha'; } } if (count($errors) > 0) $fjson = json_encode($errors); else $fjson = json_encode($context); $res = '{' . '"status":200,' . '"datajson":' . $fjson . '}'; return $res; } Ideally, my json should reply with authentication token and context related info to app whenever asked with username and password. Link to comment Share on other sites More sharing options...
TheLousyCoder Posted January 19, 2015 Author Share Posted January 19, 2015 Well, Problem resolved . It was just a spelling mistake of "context" line $contaxt = Context::getContext(); should be $context = Context::getContext(); Link to comment Share on other sites More sharing options...
Dev Franco Posted July 10, 2015 Share Posted July 10, 2015 Hi all, I am newbie to prestashop. I need your valuable suggestionson the following regard. 1) If develop a mobile app using API from Prestashop as backend, will the mobile app can have all the Cart/Shipping/Catalog rules added in the Prestashop web admin?2) If change any configuration settings in Prestashop admin, will it be available in mobile app tooIn short , whether the changes made in Prestashop admin shall be available for both Web and mobile apps and will they work in similar fashion. Please respond with your suggestions. Thanks in advance. Link to comment Share on other sites More sharing options...
Recommended Posts