Prestashop: Session cookies & login

2019-01-27 10:09发布

问题:

I would like some help with the fundamentals for making a centralized logon (front office) for Prestashop - a separate logon page.

I have a Prestashop installation with multiple shops (multistore). I have tried the Webservices API but doesn't find any way to handle logins and session cookies. How do I do this?

For example: In my Prestashop I've got three shops with three different URLs, such as:

A => mydomain.com/a
B => mydomain.com/b
C => mydomain.com/c

When a customer browses to the URL, mydomain.com (top of domain) a logon page will appear.

The user logs in and gets redirected to the shop where he/she is registered.

So to get started with my project I would like know how to login a user through a page outside Prestashop. Can I load classes from PS and use them externally?

UPDATE 1: I tried to retrive cookie data from mydomain.com/login/cookie.php:

include_once('../config/config.inc.php');
include_once('../config/settings.inc.php');
include_once('../classes/Cookie.php');
$cookie = new Cookie('ps'); // Use "psAdmin" to read an employee's cookie

if(!$cookie->isLogged()){
  echo ("Please login");
  exit;
}
else{
  echo ("Logged in as: ".$cookie->customer_lastname." ".$cookie->customer_firstname);
}

Eventough I was logged in at one of my shops (mydomain.com/b) the code (mydomain.com/login/cookie.php) says I'm not logged in. What am I doing wrong

UPDATE 2: This works but just for the first shop. I'm not able to collect data from the other shops in the same shop group.

include_once('../config/config.inc.php');
include_once('../config/settings.inc.php');
include_once('../classes/Cookie.php');
$lastname=Context::getContext()->customer->lastname;

if(!Context::getContext()->customer->isLogged()){
    echo "Please login";
    exit;
}
else{
    echo "Logged in as".$lastname;
    exit;   
}

回答1:

password is SALTED in prestashop config.ini.php and you might have different versions which code the cookie differently.