Jump to content

Webservice login customer Prestashop 1.7


arleyhr

Recommended Posts

  • 4 years later...

Hello!
I need to get a user of my website to login to the prestashop ecommerce. With the APi I managed to validate the email and password, now I only need that when I refresh the ecomerce, I appear logged in. Any suggestion?

My version prestashop is: 1.7.6.4
My code is the following

//--------------Login
// get information from PrestaShop
$ webService = new PrestaShopWebservice ('https://www.xxxxx.com/', 'XXXXXXXXXXXXXXXXXXXX', false);

$ email = '[email protected]'; // $ _REQUEST ['email'];
$ password = 'XXXXX';
// $ password = $ _REQUEST ['password'];

$ optUser = array (
'resource' => 'customers',
'filter [email]' => '['. $ email. ']',
'display' => '[id, email, lastname, firstname, passwd]'
);

$ resultUser = ($ webService-> get ($ optUser));

foreach ($ resultUser-> customers-> customer as $ info) {

if (password_verify ($ password, $ info-> passwd) == true) {
$ response = array ();
$ response ['status'] = 'succes';
$ response ['message'] = "You did it!";
setcookie ("userId", $ info-> id);

$ _SESSION ['user'] = $ email;
header ('Content-type: application / json');

echo json_encode ($ response);

echo '<br>'. $ info-> passwd;
echo '<br>'. $ cook;
} else {
$ response = array ();
$ response ['status'] = 'error';
$ response ['message'] = 'Wrong password';
header ('Content-type: application / json');
echo json_encode ($ response);
}
}

Edited by mastlucas (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...