Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // code placeholder
- require_once('./PSWebServiceLibrary.php');
- include('./config/settings.inc.php');
- /**
- * get information from PrestaShop
- */
- $webService = new PrestaShopWebservice('mydomain', 'mykey', false);
- $COOKIE_KEY = '4pUiDR9UDX2j475qhnjX6WaI3H6L8FUthMfpIACui1sj1WvMvtnLj5aK';
- $email = 'email';
- $password = 'password';
- $optUser = array(
- 'resource' => 'customers',
- 'filter[email]' => '[' . $email . ']',
- 'display' => '[id,email,lastname,firstname,passwd]'
- );
- $resultUser = ($webService->get($optUser));
- $json = json_encode($resultUser);
- foreach ($resultUser->customers->customer as $info) {
- // Prestashop uses the cookie_key in combination with a salt key. To check
- the password use the php function: password_verify();
- $salt = substr($info->passwd, strrpos($info->passwd, ':') + 1, 2);
- $ZCpassword = md5($COOKIE_KEY . $password) . ':' . $salt;
- // Check if password comparison is true or false
- if (password_verify($password, $info->passwd) == true) {
- session_start();
- $response = array();
- $response['status'] = 'success';
- $response['message'] = "You did it!";
- setcookie("userId", $info->id);
- header('Content-type: application/json');
- echo json_encode($response);
- } else {
- $response = array();
- $response['status'] = 'error';
- $response['message'] = 'Wrong password';
- header('Content-type: application/json');
- echo json_encode($response);
- }
- }
- ?>
- try {
- // creating web service access
- $webService = new PrestaShopWebservice('http://example.com/', 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT', false);
- // call to retrieve all customers
- $xml = $webService->get(array('resource' => 'customers'));}catch (PrestaShopWebserviceException $ex) {
- // Shows a message related to the error
- echo 'Other error: <br />' . $ex->getMessage();}
Add Comment
Please, Sign In to add comment