From 0260ae7719a25b8837c0629780685d6b8e728724 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Wed, 6 Dec 2017 09:53:42 -0600 Subject: [PATCH] CRM-21526: CRM_Utils_System_Drupal8::authenticate() should change the current Drupal user --- CRM/Utils/System/Drupal8.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 09f102b75af4..be2bb03a6ffe 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -365,9 +365,14 @@ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realP $system->loadBootStrap(array(), FALSE); $uid = \Drupal::service('user.auth')->authenticate($name, $password); - $contact_id = CRM_Core_BAO_UFMatch::getContactId($uid); + if ($uid) { + if ($this->loadUser($name)) { + $contact_id = CRM_Core_BAO_UFMatch::getContactId($uid); + return array($contact_id, $uid, mt_rand()); + } + } - return array($contact_id, $uid, mt_rand()); + return FALSE; } /** @@ -469,7 +474,7 @@ public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = if (!empty($params['uid']) && $username = \Drupal\user\Entity\User::load($uid)->getUsername()) { $this->loadUser($username); } - elseif (!empty($params['name']) && !empty($params['pass']) && $this->authenticate($params['name'], $params['pass'])) { + elseif (!empty($params['name']) && !empty($params['pass']) && \Drupal::service('user.auth')->authenticate($params['name'], $params['pass'])) { $this->loadUser($params['name']); } }