From b596c3e97d4a459a3085277cc3501c18be4b5e8a Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 23 Feb 2016 18:18:51 +0530 Subject: [PATCH] CRM-17968 -- load users for joomla and WP --- CRM/Utils/System/Joomla.php | 25 +++++++++++++++++++++---- CRM/Utils/System/WordPress.php | 17 ++++++++++++++--- bin/cli.class.php | 2 +- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index b063d70adb..0176be5bbc 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -430,13 +430,30 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } /** - * FIXME: Do something - * - * @param \obj $user + * @param \string $username + * @param \string $password * * @return bool */ - public function loadUser($user) { + public function loadUser($username, $password = NULL) { + $uid = JUserHelper::getUserId($username); + if (empty($uid)) { + return FALSE; + } + $contactID = CRM_Core_BAO_UFMatch::getContactId($uid); + if (!empty($password)) { + $instance = JFactory::getApplication('site'); + $params = array( + 'username' => $username, + 'password' => $password, + ); + //perform the login action + $instance->login($params); + } + + $session = CRM_Core_Session::singleton(); + $session->set('ufID', $uid); + $session->set('userID', $contactID); return TRUE; } diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 4f8c32b305..b927e16082 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -326,13 +326,24 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** - * FIXME: Do something - * - * @param \obj $user + * @param \string $user * * @return bool */ public function loadUser($user) { + $userdata = get_user_by('login', $user); + if (!$userdata->data->ID) { + return false; + } + + $uid = $userdata->data->ID; + wp_set_current_user($uid); + $contactID = CRM_Core_BAO_UFMatch::getContactId($uid); + + // lets store contact id and user id in session + $session = CRM_Core_Session::singleton(); + $session->set('ufID', $uid); + $session->set('userID', $contactID); return TRUE; } diff --git a/bin/cli.class.php b/bin/cli.class.php index a051135620..dbcc5e9caf 100644 --- a/bin/cli.class.php +++ b/bin/cli.class.php @@ -269,7 +269,7 @@ class civicrm_cli { $this->_log(ts("Failed to login as %1. Wrong username or password.", array('1' => $this->_user))); return FALSE; } - if (!$cms->loadUser($this->_user)) { + if (($this->_config->userFramework == 'Joomla' && !$cms->loadUser($this->_user, $this->_password)) || !$cms->loadUser($this->_user)) { $this->_log(ts("Failed to login as %1", array('1' => $this->_user))); return FALSE; } -- 2.25.1