vocabo Posted May 20, 2011 Share Posted May 20, 2011 Hello, how to make a login box in an external page?Thanks! Link to comment Share on other sites More sharing options...
vocabo Posted May 21, 2011 Author Share Posted May 21, 2011 Thank you angora,basically I shuld send a POST request to the PrestaShop authentication.php file with params 'email' and 'passwd'. Link to comment Share on other sites More sharing options...
vocabo Posted May 25, 2011 Author Share Posted May 25, 2011 Can I do this with some PrestaShop php function? Link to comment Share on other sites More sharing options...
vocabo Posted May 25, 2011 Author Share Posted May 25, 2011 I need to log in the user from my page and to control where the user will be redirected. The problem with the first suggestion was that when I send a POST request to the authetication.php page with params as described, it doesn't log in the user, but load the login page with already filled in username and password. May be it needs some more params to be more cooperative .Thank you for your help! Link to comment Share on other sites More sharing options...
vocabo Posted May 26, 2011 Author Share Posted May 26, 2011 I figured this out! I ended up with this php function: function psLogin($email, $password) { global $cookie; $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($password)); if ( $authentication and $customer->id ) { $cookie->logged = 1; $cookie->id_customer = intval($customer->id); $cookie->customer_lastname = $customer->lastname; $cookie->customer_firstname = $customer->firstname; $cookie->passwd = $customer->passwd; $cookie->email = $customer->email; Module::hookExec('authentication'); return true; } else { return false; } } It works exactly as I needed . Link to comment Share on other sites More sharing options...
MarcoPas Posted June 28, 2011 Share Posted June 28, 2011 I need this to, could you explain a little bit more on how you integrated this? My usecase is that i need a login box on a seperate html/php page and after a succesfulllogin the normal shop page should be loaded. Link to comment Share on other sites More sharing options...
Ehinarr Posted June 28, 2011 Share Posted June 28, 2011 I need this to, could you explain a little bit more on how you integrated this? My usecase is that i need a login box on a seperate html/php page and after a succesfulllogin the normal shop page should be loaded. What You need is something like this?Pre Login Module for PS v1.3.7 Link to comment Share on other sites More sharing options...
MarcoPas Posted June 29, 2011 Share Posted June 29, 2011 If you create a custom prestashop php function, how would you call this function from a separate html form? Link to comment Share on other sites More sharing options...
MarcoPas Posted June 30, 2011 Share Posted June 30, 2011 Excuse me if my question seems stupid, but could you give me a small example or place where i can look on how to create a handler for PrestaShop? I would like to create a form and submit the username/password and if succesfull redirect to another page. Link to comment Share on other sites More sharing options...
gugu Posted December 8, 2013 Share Posted December 8, 2013 (edited) yes please I need it too the link above to the modul is not working ! Edited December 8, 2013 by gugu (see edit history) Link to comment Share on other sites More sharing options...
Krita Posted April 3, 2014 Share Posted April 3, 2014 I figured this out! I ended up with this php function: function psLogin($email, $password) { global $cookie; $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($password)); if ( $authentication and $customer->id ) { $cookie->logged = 1; $cookie->id_customer = intval($customer->id); $cookie->customer_lastname = $customer->lastname; $cookie->customer_firstname = $customer->firstname; $cookie->passwd = $customer->passwd; $cookie->email = $customer->email; Module::hookExec('authentication'); return true; } else { return false; } } It works exactly as I needed . I have a similar problem. I see that the post is marked solved. However, I do not understand where to implement the code. Sorry if I am being too dumb. I am actually a newbie in it. Link to comment Share on other sites More sharing options...
jarda82 Posted August 30, 2021 Share Posted August 30, 2021 Here is solution that works for me in 1.7 $authentication = $customer->getByEmail($email, $password); $authentication->logged = 1; $this->context->customer = $authentication; $this->context->cookie->id_customer = (int) $authentication->id; $this->context->cookie->customer_lastname = $authentication->lastname; $this->context->cookie->customer_firstname = $authentication->firstname; $this->context->cookie->logged = 1; $this->context->cookie->check_cgv = 1; $this->context->cookie->is_guest = false; $this->context->cookie->passwd = $authentication->passwd; $this->context->cookie->email = $authentication->email; $this->context->cookie->registerSession(new CustomerSession()); Link to comment Share on other sites More sharing options...
SherZad Posted September 22, 2021 Share Posted September 22, 2021 Hi everyone! I figured I could share a piece of code. It might help one or the other 😀 I'm curretly working on the major 1.7.7. /** * Updates the customer in the context of the shop * * @param Customer $customer * @return bool */ private function loginCustomer(Customer $customer) { try { // update customer does all the work $this->context->updateCustomer($customer); } catch (Exception | PrestaShopException $e) { return false; } return true; } And a simple authenticate use case could look like this: /** * Tries to authenticate a customer with the given email address * * @param string $mail A valid email address * @return bool Returns true is authenticated */ private function authenticateCustomer($mail) { try { $customer = ''; // check whether a customer with the given email address already exists if (!Customer::customerExists($mail)) { // if the customer doesn't exist -> create // you can use your own create function with your preferred way. It should return a Customer object $customer = $this->createCustomer(); } else { // or if a user already exists // get the existing customer object by mail $customer = (new Customer())->getByEmail(trim($mail)); } // finally login the customer $this->loginCustomer($customer); } catch (Exception | PrestaShopException $e) { return false; } return true; } I hope this helps. Cheers! 1 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