From c1f3c6da6aafa56b379e8877525fa497ef481776 Mon Sep 17 00:00:00 2001 From: Brian Shaughnessy Date: Tue, 11 Feb 2014 23:10:17 -0500 Subject: [PATCH] CRM-14208, CRM-14140 use more of jsproffitt patch to simplify logic --- CRM/Utils/Hook/Joomla.php | 1 + CRM/Utils/System/Joomla.php | 75 +++++++++++++------------------------ bin/cli.class.php | 4 +- 3 files changed, 31 insertions(+), 49 deletions(-) diff --git a/CRM/Utils/Hook/Joomla.php b/CRM/Utils/Hook/Joomla.php index 94d7f0a58e..459e195497 100644 --- a/CRM/Utils/Hook/Joomla.php +++ b/CRM/Utils/Hook/Joomla.php @@ -44,6 +44,7 @@ class CRM_Utils_Hook_Joomla extends CRM_Utils_Hook { if (defined('_JEXEC')) { //Invoke the Joomla plugin system to observe to civicrm events. jimport('joomla.plugin.helper'); + jimport('cms.plugin.helper'); JPluginHelper::importPlugin('civicrm'); // get app based on cli or web diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index fcbf34b7ca..4db4125cf1 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -471,6 +471,22 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { jimport('joomla.application.component.helper'); jimport('joomla.database.table'); + jimport('joomla.user.helper'); + + $JUserTable = JTable::getInstance('User', 'JTable'); + + $db = $JUserTable->getDbo(); + $query = $db->getQuery(TRUE); + $query->select('id, name, username, email, password'); + $query->from($JUserTable->getTableName()); + $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)'); + $db->setQuery($query, 0, 0); + $users = $db->loadObjectList(); + + $row = array(); + if (count($users)) { + $row = $users[0]; + } if ( !defined('JVERSION') ) { $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))); @@ -479,30 +495,14 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { define('JVERSION', $jversion->getShortVersion()); } - if ( version_compare(JVERSION, '2.5.18', 'lt') || - ( version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.2', 'lt') ) - ) { - //old method for authenticating - $JUserTable = JTable::getInstance('User', 'JTable'); - - $db = $JUserTable->getDbo(); - $query = $db->getQuery(TRUE); - $query->select('id, username, email, password'); - $query->from($JUserTable->getTableName()); - $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)'); - $db->setQuery($query, 0, 0); - $users = $db->loadAssocList(); - - $row = array();; - if (count($users)) { - $row = $users[0]; - } - - if (!empty($row)) { - $dbPassword = CRM_Utils_Array::value('password', $row); - $dbId = CRM_Utils_Array::value('id', $row); - $dbEmail = CRM_Utils_Array::value('email', $row); + if (!empty($row)) { + $dbPassword = $row->password; + $dbId = $row->id; + $dbEmail = $row->email; + if ( version_compare(JVERSION, '2.5.18', 'lt') || + ( version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.1', 'lt') ) + ) { // now check password if (strpos($dbPassword, ':') === FALSE) { if ($dbPassword != md5($password)) { @@ -517,39 +517,18 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { } } } - } - else { - //new authentication method (J2.5.18/3.2.2 and greater) - // Get a database object - $db = JFactory::getDbo(); - $query = $db->getQuery(TRUE); - - $query->select('id, password'); - $query->from('#__users'); - $query->where('username='.$db->quote($name)); - - $db->setQuery( $query ); - $result = $db->loadObject(); - - if ($result) { - $match = JUserHelper::verifyPassword($password, $result->password, $result->id); - - if ($match === TRUE) { - $jUser = JUser::getInstance($result->id); // Bring this in line with the rest of the system - $dbId = $row['id'] = $result->id; - $dbEmail = $row['email'] = $jUser->email; - } + else { + if (!JUserHelper::verifyPassword($password, $dbPassword, $dbId)) return FALSE; } - } - if (!empty($row)) { - CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $dbId, $dbEmail, 'Joomla'); + CRM_Core_BAO_UFMatch::synchronizeUFMatch($row, $dbId, $dbEmail, 'Joomla'); $contactID = CRM_Core_BAO_UFMatch::getContactId($dbId); if (!$contactID) { return FALSE; } return array($contactID, $dbId, mt_rand()); } + return FALSE; } diff --git a/bin/cli.class.php b/bin/cli.class.php index 1e44a962a7..de72c475b4 100644 --- a/bin/cli.class.php +++ b/bin/cli.class.php @@ -201,7 +201,9 @@ class civicrm_cli { chdir($civicrm_root); require_once ('civicrm.config.php'); // autoload - require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; + if ( !class_exists('CRM_Core_ClassLoader') ) { + require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; + } CRM_Core_ClassLoader::singleton()->register(); $this->_config = CRM_Core_Config::singleton(); -- 2.25.1