これは、ログイン画面を経由せずに prestashop にユーザーをログインさせる方法のチュートリアルです。これは、セッションを 1 つの Web サイトから prestashop に転送する場合のように、ユーザーに再度ログインさせたくない場合に役立ちます。
ステップ 1 パスワードのソルティングを不要にします。config/settings.inc.php で、_COOKIE_KEY_ を空白に設定します。これは、新しい顧客を作成する必要があることも意味することに注意してください。または、DB から古い md5 パスワードを削除して、独自のパスワードを追加することもできます。
ステップ 2 authentication.php ファイルで、6 行目の後に次の行を貼り付けます。
$customer = new Customer();
//$authentication = $customer->getByEmail(trim($email), trim($passwd));
$authentication = $customer->getByMd5(trim($email), trim($passwd)); //modified version of getByEmail if we are not accepting $passwd in cleartext but in md5.
/* Handle brute force attacks */
sleep(1);
if (!$authentication OR !$customer->id)
$errors[] = Tools::displayError('authentication failed');
else
{
$cookie->id_customer = intval($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->logged = 1;
$cookie->passwd = $customer->passwd;
$cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') AND (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0))
$cookie->id_cart = intval(Cart::lastNoneOrderedCart(intval($customer->id)));
Module::hookExec('authentication');
if ($back = Tools::getValue('back'))
Tools::redirect($back);
//Tools::redirect('my-account.php'); //cut redirection to break infinite loop
}
上記のコードは、プレーンテキストで $email をユーザー名として、$passwd をパスワードとして使用してユーザーをログインさせるものです。元のコードはif (Tools::isSubmit('SubmitLogin'))
、authentication.php ファイル内の関数から取得されます。
ステップ 3 上記のコードを products.php ファイルの 5 行目のすぐ下に貼り付けます。
ステップ 4 $passwd を md5 形式で直接送信する場合は、getByEmail()(customer.php) の修正版を次に示します。
public function getByMd5($email, $passwd = NULL)
{
$result = Db::getInstance()->GetRow('SELECT * FROM `'._DB_PREFIX_ .'customer` WHERE `active` = 1 AND `email` = \''.pSQL($email).'\' '.(isset($passwd) ? 'AND `passwd` = \''.pSQL(_COOKIE_KEY_.$passwd).'\'' : '').' AND `deleted` = 0');
if (!$result)
return false;
$this->id = $result['id_customer'];
foreach ($result AS $key => $value)
if (key_exists($key, $this))
$this->{$key} = $value;
return $this;
}
$_COOKIE[] 関数または $_GET[] のいずれかを使用して、ユーザー名/パスワードにアクセスできます。いずれにせよ、それは大きなセキュリティリスクです。Cookie の読み取りは、index.php ファイルに配置できます。