2013-11-14 44 views
2

我必須將PrestaShop 1.5與預先存在的symfony應用程序集成。prestashop用戶登錄集成

通過webservices,我可以保持數據庫同步,因此用戶可以使用PrestaShop和應用程序軟件上的相同數據執行登錄。 現在我想確保在應用程序中登錄,用戶自動登錄到PrestaShop平臺。

你能幫我嗎?

+0

你好,Prestashop 1.4或1.5? –

+0

1.5正如我寫的謝謝 –

+0

老問題肯定,但可以看看這個,https://github.com/hparfr/prestashopBridge – PatrickS

回答

1

我不知道你是否仍在尋找解決方案,但實際上有一種方法。

請確保它是安全登錄。

由於您允許訪問所有prestashop數據,請確保登錄非常安全。我已經能夠用PHP重新創建它我認爲有了一些補充,你可以按照你想要的方式重新創建它。將其作爲指導。

要使用的Prestashop Web服務創建一個登錄系統,您將需要三樣東西

通過網絡服務來爲客戶表 的COOKIE_KEY,在app/config中定義的訪問 - > parameters.php ::「cookie_key」 =>'12321test'; PHP 一些有效首先是從web服務獲取customers表。

// code placeholder 
require_once('./../PSWebServiceLibrary.php'); 

/** 
* get information from PrestaShop 
*/ 

$webService = new PrestaShopWebservice($url, $key, $debug); 

$COOKIE_KEY = 'CookieKey'; 
$email = $_REQUEST['email']; 
$password = $_REQUEST['password']; 

$optUser = array(
    'resource' => 'customers', 
    'filter[email]' => '[' . $email . ']', 
    'display' => '[id,email,lastname,firstname,passwd]' 
); 

$resultUser = ($webService->get($optUser)); 

$json = json_encode($resultUser); 

第二,也是最重要的事情是檢查用戶輸入

// code placeholder 

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'] = 'succes'; 
     $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); 
    } 
} 

這是如何重現問題的工作示例。

我用的是設置cookie並檢查它是否存在!

希望這會有所幫助!