Guest User

Untitled

a guest
Sep 11th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?php
  2. // code placeholder
  3. require_once('./PSWebServiceLibrary.php');
  4. include('./config/settings.inc.php');
  5.  
  6. /**
  7. * get information from PrestaShop
  8. */
  9.  
  10. $webService = new PrestaShopWebservice('mydomain', 'mykey', false);
  11.  
  12. $COOKIE_KEY = '4pUiDR9UDX2j475qhnjX6WaI3H6L8FUthMfpIACui1sj1WvMvtnLj5aK';
  13. $email = 'email';
  14. $password = 'password';
  15.  
  16. $optUser = array(
  17. 'resource' => 'customers',
  18. 'filter[email]' => '[' . $email . ']',
  19. 'display' => '[id,email,lastname,firstname,passwd]'
  20. );
  21.  
  22. $resultUser = ($webService->get($optUser));
  23.  
  24. $json = json_encode($resultUser);
  25.  
  26. foreach ($resultUser->customers->customer as $info) {
  27. // Prestashop uses the cookie_key in combination with a salt key. To check
  28. the password use the php function: password_verify();
  29. $salt = substr($info->passwd, strrpos($info->passwd, ':') + 1, 2);
  30. $ZCpassword = md5($COOKIE_KEY . $password) . ':' . $salt;
  31.  
  32. // Check if password comparison is true or false
  33. if (password_verify($password, $info->passwd) == true) {
  34. session_start();
  35. $response = array();
  36. $response['status'] = 'success';
  37. $response['message'] = "You did it!";
  38. setcookie("userId", $info->id);
  39. header('Content-type: application/json');
  40. echo json_encode($response);
  41. } else {
  42. $response = array();
  43. $response['status'] = 'error';
  44. $response['message'] = 'Wrong password';
  45. header('Content-type: application/json');
  46. echo json_encode($response);
  47. }
  48. }
  49.  
  50. ?>
  51.  
  52. try {
  53. // creating web service access
  54. $webService = new PrestaShopWebservice('http://example.com/', 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT', false);
  55.  
  56. // call to retrieve all customers
  57. $xml = $webService->get(array('resource' => 'customers'));}catch (PrestaShopWebserviceException $ex) {
  58. // Shows a message related to the error
  59. echo 'Other error: <br />' . $ex->getMessage();}
Add Comment
Please, Sign In to add comment