Drupal 7 使用drupal的Magento帐户进行单次登录
我有自定义的Magento脚本文件,如下所示,只需向该PHP文件发送电子邮件和密码即可登录 当我从浏览器打电话时,它工作正常 但是,我想通过我创建的Drupal模块进行此调用 正如我所料,Drupal模块正在调用,我也收到了成功消息。但是登录没有发生 我的直觉是,magento有一些登录限制,这些限制发生在magento根文件夹之外 请查找以下来源。 Drupal目录-/www/Drupal/ Magento目录-/www/drupal/store/ /www/drupal/store/api_config.phpDrupal 7 使用drupal的Magento帐户进行单次登录,drupal-7,magento-1.9,Drupal 7,Magento 1.9,我有自定义的Magento脚本文件,如下所示,只需向该PHP文件发送电子邮件和密码即可登录 当我从浏览器打电话时,它工作正常 但是,我想通过我创建的Drupal模块进行此调用 正如我所料,Drupal模块正在调用,我也收到了成功消息。但是登录没有发生 我的直觉是,magento有一些登录限制,这些限制发生在magento根文件夹之外 请查找以下来源。 Drupal目录-/www/Drupal/ Magento目录-/www/drupal/store/ /www/drupal/store/api_
/www/drupal/sites/all/modules/single\u signon/single\u signon.module
任何关于解决这个谜团的发现的建议都会非常有用。我不确定是否能很好地理解它:您有一个php脚本,它使用URL中的数据发送(GET)来连接会话中的用户。您希望Drupal服务器使用它直接连接到您的Magento 我认为您的代码正在工作,但不幸的是,它无法帮助用户连接到Magento 由于这是请求连接的Drupal服务器,将连接的是Drupal服务器会话,而不是导航用户会话。 如果用户必须在其navigator中连接到Magento服务器,则必须是navigator服务器,该服务器必须直接调用Magento脚本。 我认为这可以在iframe中完成,也可以通过Ajax完成 我认为您还可以找到其他一些解决方案,比如OAuth,但它需要更多的编码 编辑 关于你的问题,我发现了一些有趣的话题:
if ($response['status']=='success') {
...
setcookie('frontend', $response['sessionId'], time() + 3600 * 24 * 180, '/');
...
}
您可能需要在Magento的设置中声明位于“/”的Cookie路径
您能举一个来自Magento的会话cookie的结构示例吗?即使您不喜欢我的答案,我真的认为它不能像现在这样工作。Magento脚本必须将会话信息发送回Drupal,以允许您的模块在用户的导航器上记录Magento的会话cookie。
<?php
require_once "api_config.php";
$session = Mage::getSingleton('customer/session');
//$session->start();
if (isset($_GET['email']) && !empty($_GET['email']) && isset($_GET['password']) && !empty($_GET['password'] )) {
if (!filter_var($_GET['email'], FILTER_VALIDATE_EMAIL) === false) {
$email = $_GET['email'];
$password = $_GET['password'];
try {
if ($session->login($email, $password )) {
$response['status'] = 'success';
$response['data'] = array($_GET);
$response['message'] = array('User loggedin Successfully.');
} else {
$response['status'] = 'error';
$response['data'] = array($_GET);
$response['message'] = array('User login failed.');
}
if ($session->getCustomer()->getIsJustConfirmed()) {
$this->_welcomeCustomer($session->getCustomer(), true);
}
} catch (Mage_Core_Exception $e) {
switch ($e->getCode()) {
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
$value = Mage::helper('customer')->getEmailConfirmationUrl($email);
$message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
break;
default:
$message = $e->getMessage();
}
//$session->addError($message);
$response['status'] = 'error';
$response['data'] = array($_GET);
$response['message'] = array($message);
echo $message;
$session->setUsername($email);
} catch (Exception $e) {
$response['status'] = 'error';
$response['data'] = array($_GET);
$response['message'] = array($e);
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
}
} else {
//$session->addError('Login and password are required.');
$response['status'] = 'error';
$response['data'] = array($_GET);
$response['message'] = array('Invalid Email address');
}
} else {
//$session->addError('Login and password are required.');
$response['status'] = 'error';
$response['data'] = array($_GET);
$response['message'] = array('Login and password are required.');
}
print_r(json_encode($response, JSON_FORCE_OBJECT));die;
?>
<?php
function single_signon_user_login(&$edit, $account) {
//store variable values
$postData = array();
$postData['email'] = $account->mail;
$postData['password'] = $edit['input']['pass'];
$inc = 1; //count of registration
if (!empty($postData['email']) && !empty($postData['password'])) {
// use of drupal_http_request
$data = http_build_query($postData, '', '&');
//$url = url('http://127.0.0.1/drupal/store/api_login.php?'.$data);
//$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
//print_r($url);
// the actual sending of the data
$JSONresponse = drupal_http_request('http://127.0.0.1/drupal/store/api_login.php?email=john@example.com&password=password');
//print_r($JSONresponse);die;
$response = json_decode($JSONresponse->data, true);
if ($response['status']=='success') {
$inc+=1;
$message = 'Logged in successfully('.$inc.')';
drupal_set_message($message, $type = 'status', $repeat = FALSE); //message goes here
} else {
$message = 'Logged in failed. Due to '.$response['message'].'('.$inc.')';
drupal_set_message($message, $type = 'error ', $repeat = FALSE);
}
} else {
$message = 'Not able to log inside store('.$inc.')';
drupal_set_message($message, $type = 'status', $repeat = FALSE); //message goes here
}
}
?>
$response['sessionId'] = $session->getEncryptedSessionId();
if ($response['status']=='success') {
...
setcookie('frontend', $response['sessionId'], time() + 3600 * 24 * 180, '/');
...
}