CRM-21526: CRM_Utils_System_Drupal8::authenticate() should change the current Drupal...
authorDavid Snopek <dsnopek@gmail.com>
Wed, 6 Dec 2017 15:53:42 +0000 (09:53 -0600)
committerDavid Snopek <dsnopek@gmail.com>
Wed, 6 Dec 2017 15:53:42 +0000 (09:53 -0600)
CRM/Utils/System/Drupal8.php

index 09f102b75af41989f7e399eb4a0c12903534df8d..be2bb03a6ffed003efd8ebeb30ad82b103bae7e6 100644 (file)
@@ -365,9 +365,14 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase {
     $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 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase {
       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']);
       }
     }