From: Brian Shaughnessy Date: Wed, 12 Feb 2014 04:10:17 +0000 (-0500) Subject: CRM-14208, CRM-14140 use more of jsproffitt patch to simplify logic X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c1f3c6da6aafa56b379e8877525fa497ef481776;p=civicrm-core.git CRM-14208, CRM-14140 use more of jsproffitt patch to simplify logic --- 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();