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);
}
}