static function contactID($ufID) { $contactID = CRM_Core_BAO_UFMatch::getContactId($ufID); if ($contactID) { return $contactID; } // else synchronize contact for this user $account = user_load($ufID); CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $ufID, $account->mail, 'Drupal'); $contactID = CRM_Core_BAO_UFMatch::getContactId($ufID); if (!$contactID) { CRM_Core_Error::fatal(); } return $contactID; }
/** * @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; }
/** * @inheritDoc */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { require_once 'DB.php'; $config = CRM_Core_Config::singleton(); $user = NULL; if ($loadCMSBootstrap) { $bootStrapParams = array(); if ($name && $password) { $bootStrapParams = array('name' => $name, 'pass' => $password); } CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, FALSE); } 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]; } $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))); if (!defined('JVERSION')) { require $joomlaBase . '/libraries/cms/version/version.php'; $jversion = new JVersion(); define('JVERSION', $jversion->getShortVersion()); } 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 list($hash, $salt) = explode(':', $dbPassword); $cryptpass = md5($password . $salt); if ($hash != $cryptpass) { return FALSE; } } else { if (!JUserHelper::verifyPassword($password, $dbPassword, $dbId)) { return FALSE; } //include additional files required by Joomla 3.2.1+ if (version_compare(JVERSION, '3.2.1', 'ge')) { require_once $joomlaBase . '/libraries/cms/application/helper.php'; require_once $joomlaBase . '/libraries/cms/application/cms.php'; require_once $joomlaBase . '/libraries/cms/application/administrator.php'; } } 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; }
/** * Verify if the user has permission to get the invoice. * * @return bool * TRUE if the user has download all invoices permission or download my * invoices permission and the invoice author is the current user. */ public static function checkDownloadInvoice() { global $user; $cid = CRM_Core_BAO_UFMatch::getContactId($user->uid); if (CRM_Core_Permission::check('access CiviContribute') || CRM_Core_Permission::check('view my invoices') && $_GET['cid'] == $cid) { return TRUE; } return FALSE; }
/** * get the contact_id given a uf_id * * @param int $ufID * * @return int contact_id * @access public * @static */ function crm_uf_get_match_id($ufID) { require_once 'CRM/Core/BAO/UFMatch.php'; return CRM_Core_BAO_UFMatch::getContactId($ufID); }
/** * Determine a contact ID using a string expression. * * @param string $contactIdExpr * E.g. "user_contact_id" or "@user:username". * * @return int|NULL|'unknown-user' */ function _civicrm_api3_resolve_contactID($contactIdExpr) { // If value = 'user_contact_id' replace value with logged in user id. if ($contactIdExpr == "user_contact_id") { return CRM_Core_Session::getLoggedInContactID(); } elseif (preg_match('/^@user:(.*)$/', $contactIdExpr, $matches)) { $config = CRM_Core_Config::singleton(); $ufID = $config->userSystem->getUfId($matches[1]); if (!$ufID) { return 'unknown-user'; } $contactID = CRM_Core_BAO_UFMatch::getContactId($ufID); if (!$contactID) { return 'unknown-user'; } return $contactID; } return NULL; }
} ?> </table> <?php if (isset($this->params)) { echo $this->params->render('params'); } ?> <?php require_once 'administrator/components/com_civicrm/civicrm.settings.php'; require_once 'CRM/Core/Config.php'; $civiConfig =& CRM_Core_Config::singleton(); $civiConfig->formKeyDisable = true; require_once 'CRM/Core/BAO/UFMatch.php'; $userID = CRM_Core_BAO_UFMatch::getContactId($this->user->id); require_once 'CRM/Core/BAO/UFGroup.php'; echo CRM_Core_BAO_UFGroup::getEditHTML($userID, null, 2, true, true, null, false, 'Individual'); ?> <button class="button" type="submit" onclick="submitbutton( this.form );return false;"><?php echo JText::_('Save'); ?> </button> <input type="hidden" name="username" value="<?php echo $this->user->get('username'); ?> " /> <input type="hidden" name="id" value="<?php echo $this->user->get('id');
/** * Save user registration and notify users and admins if required * @return void */ function register_save() { global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // Get required system objects $user = clone JFactory::getUser(); $pathway =& $mainframe->getPathway(); $config =& JFactory::getConfig(); $authorize =& JFactory::getACL(); $document =& JFactory::getDocument(); // If user registration is not allowed, show 403 not authorized. $usersConfig =& JComponentHelper::getParams('com_users'); if ($usersConfig->get('allowUserRegistration') == '0') { JError::raiseError(403, JText::_('Access Forbidden')); return; } // do civicrm validation here require_once 'administrator/components/com_civicrm/civicrm.settings.php'; require_once 'CRM/Core/Config.php'; $civiConfig =& CRM_Core_Config::singleton(); $civiConfig->formKeyDisable = true; require_once 'CRM/Core/BAO/UFGroup.php'; $errors = CRM_Core_BAO_UFGroup::isValid(null, null, true); if (is_array($errors)) { $msg = null; foreach ($errors as $name => $error) { $msg .= "{$name}: {$error}<br/>"; } JError::raiseWarning('', JText::_($msg)); $this->register(); return false; } // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $newUsertype = 'Registered'; } // Bind the post array to the user object if (!$user->bind(JRequest::get('post'), 'usertype')) { JError::raiseError(500, $user->getError()); } // Set some initial user values $user->set('id', 0); $user->set('usertype', ''); $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO')); $date =& JFactory::getDate(); $user->set('registerDate', $date->toMySQL()); // If user activation is turned on, we need to set the activation information $useractivation = $usersConfig->get('useractivation'); if ($useractivation == '1') { jimport('joomla.user.helper'); $user->set('activation', md5(JUserHelper::genRandomPassword())); $user->set('block', '1'); } // If there was an error with registration, set the message and display form if (!$user->save()) { JError::raiseWarning('', JText::_($user->getError())); $this->register(); return false; } // Send registration confirmation mail $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW); $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password); //Disallow control chars in the email UserController::_sendMail($user, $password); // if this was a successful save, call civicrm code to save the contact if ($user->id) { require_once 'CRM/Core/BAO/UFMatch.php'; CRM_Core_BAO_UFMatch::synchronize($user, true, 'Joomla', 'Individual'); $userID = CRM_Core_BAO_UFMatch::getContactId($user->id); if ($userID) { require_once 'CRM/Core/BAO/UFGroup.php'; CRM_Core_BAO_UFGroup::getEditHTML($userID, null, 2, true, false, null, false, 'Individual'); $session =& CRM_Core_Session::singleton(); $session->reset(); } } // Everything went fine, set relevant message depending upon user activation state and display message if ($useractivation == 1) { $message = JText::_('REG_COMPLETE_ACTIVATE'); } else { $message = JText::_('REG_COMPLETE'); } //TODO :: this needs to be replace by raiseMessage JError::raiseNotice('', $message); $this->register(); }
/** * @param \string $username * @param \string $password * * @return bool */ 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; }
/** * @inheritDoc */ public function loadUser($username) { $user = user_load_by_name($username); if (!$user) { return FALSE; } // Set Drupal's current user to the loaded user. \Drupal::currentUser()->setAccount($user); $uid = $user->id(); $contact_id = CRM_Core_BAO_UFMatch::getContactId($uid); // Store the contact id and user id in the session $session = CRM_Core_Session::singleton(); $session->set('ufID', $uid); $session->set('userID', $contact_id); return TRUE; }
/** * get the contact_id given a uf_id * * @param int $ufID * * @return int contact_id * @access public * @static */ function civicrm_uf_match_id_get($ufID) { if ((int) $ufID > 0) { require_once 'CRM/Core/BAO/UFMatch.php'; return CRM_Core_BAO_UFMatch::getContactId($ufID); } else { return civicrm_create_error('Param needs to be a positive integer.'); } }
/** * Authenticate the user against the drupal db * * @param string $name the user name * @param string $password the password for the above user name * * @return mixed false if no auth * array( contactID, ufID, unique string ) if success * @access public * @static */ static function authenticate($name, $password) { require_once 'DB.php'; $config =& CRM_Core_Config::singleton(); $dbDrupal = DB::connect($config->userFrameworkDSN); if (DB::isError($dbDrupal)) { CRM_Core_Error::fatal("Cannot connect to drupal db via {$config->userFrameworkDSN}, " . $dbDrupal->getMessage()); } $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $password = md5($password); $name = $dbDrupal->escapeSimple($strtolower($name)); $sql = 'SELECT u.* FROM ' . $config->userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '{$name}' AND u.pass = '******' AND u.status = 1"; $query = $dbDrupal->query($sql); $user = null; // need to change this to make sure we matched only one row require_once 'CRM/Core/BAO/UFMatch.php'; while ($row = $query->fetchRow(DB_FETCHMODE_ASSOC)) { CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row['uid'], $row['mail'], 'Drupal'); $contactID = CRM_Core_BAO_UFMatch::getContactId($row['uid']); if (!$contactID) { return false; } return array($contactID, $row['uid'], mt_rand()); } return false; }
/** * Authenticate the user against the joomla db * * @param string $name the user name * @param string $password the password for the above user name * @param $loadCMSBootstrap boolean load cms bootstrap? * * @return mixed false if no auth * array( contactID, ufID, unique string ) if success * @access public */ function authenticate($name, $password, $loadCMSBootstrap = FALSE) { require_once 'DB.php'; $config = CRM_Core_Config::singleton(); if ($loadCMSBootstrap) { $bootStrapParams = array(); if ($name && $password) { $bootStrapParams = array('name' => $name, 'pass' => $password); } CRM_Utils_System::loadBootStrap($bootStrapParams); } jimport('joomla.application.component.helper'); jimport('joomla.database.table'); $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]; } $user = NULL; if (!empty($row)) { $dbPassword = CRM_Utils_Array::value('password', $row); $dbId = CRM_Utils_Array::value('id', $row); $dbEmail = CRM_Utils_Array::value('email', $row); // now check password if (strpos($dbPassword, ':') === FALSE) { if ($dbPassword != md5($password)) { return FALSE; } } else { list($hash, $salt) = explode(':', $dbPassword); $cryptpass = md5($password . $salt); if ($hash != $cryptpass) { return FALSE; } } CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $dbId, $dbEmail, 'Joomla'); $contactID = CRM_Core_BAO_UFMatch::getContactId($dbId); if (!$contactID) { return FALSE; } return array($contactID, $dbId, mt_rand()); } return FALSE; }
/** * Authenticate the user against the wordpress db * * @param string $name the user name * @param string $password the password for the above user name * * @return mixed false if no auth * array( contactID, ufID, unique string ) if success * @access public * @static */ function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { $config = CRM_Core_Config::singleton(); if ($loadCMSBootstrap) { $config->userSystem->loadBootStrap($name, $password); } $user = wp_authenticate($name, $password); if (is_a($user, 'WP_Error')) { return FALSE; } // need to change this to make sure we matched only one row CRM_Core_BAO_UFMatch::synchronizeUFMatch($user->data, $user->data->ID, $user->data->user_email, 'WordPress'); $contactID = CRM_Core_BAO_UFMatch::getContactId($user->data->ID); if (!$contactID) { return FALSE; } return array($contactID, $user->data->ID, mt_rand()); }
/** * Authenticate the user against the joomla db * * @param string $name the user name * @param string $password the password for the above user name * * @return mixed false if no auth * array( contactID, ufID, unique string ) if success * @access public * @static */ static function authenticate($name, $password) { require_once 'DB.php'; $config =& CRM_Core_Config::singleton(); $dbJoomla = DB::connect($config->userFrameworkDSN); if (DB::isError($dbJoomla)) { CRM_Core_Error::fatal("Cannot connect to joomla db via {$config->userFrameworkDSN}, " . $dbJoomla->getMessage()); } $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $name = $dbJoomla->escapeSimple($strtolower($name)); $sql = 'SELECT u.* FROM ' . $config->userFrameworkUsersTableName . " u WHERE LOWER(u.username) = '{$name}' AND u.block = 0"; $query = $dbJoomla->query($sql); $user = null; require_once 'CRM/Core/BAO/UFMatch.php'; if ($row = $query->fetchRow(DB_FETCHMODE_ASSOC)) { // now check password if (strpos($row['password'], ':') === false) { if ($row['password'] != md5($password)) { return false; } } else { list($hash, $salt) = explode(':', $row['password']); $cryptpass = md5($password . $salt); if ($hash != $cryptpass) { return false; } } CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row['id'], $row['email'], 'Joomla'); $contactID = CRM_Core_BAO_UFMatch::getContactId($row['id']); if (!$contactID) { return false; } return array($contactID, $row['id'], mt_rand()); } return false; }
function loadUser($username) { global $user; $user = user_load_by_name($username); if (empty($user->uid)) { return FALSE; } $uid = $user->uid; $contact_id = 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', $contact_id); return TRUE; }
/** * Helper function to ensure a profile is created. * * This function ensures that the profile is created and if not, it * creates it. * * @return integer profile id */ function petitionemail_get_profile_id($key) { $group = 'petitionemail'; $ret = CRM_Core_BAO_Setting::getItem($group, $key); if (!empty($ret)) { // Ensure it exists $sql = "SELECT id FROM civicrm_uf_group WHERE id = %0"; $dao = CRM_Core_DAO::executeQuery($sql, array(0 => array($ret, 'Integer'))); $dao->fetch(); if ($dao->N == 1) { return $ret; } // Delete this variable - probably the user deleted the profile not knowing // what it was used for. $sql = "DELETE FROM civicrm_setting WHERE group_name = %0 AND name = %1"; $params = array(0 => array($group, 'String'), 1 => array($key, 'String')); CRM_Core_DAO::executeQuery($sql, $params); } // Create the profile // We have to manually set created_id if the current user is not set $session = CRM_Core_Session::singleton(); $contact_id = $session->get('userID'); if (empty($contact_id)) { // Maybe we are running via drush? // Try the contact associated with uid 1 $contact_id = CRM_Core_BAO_UFMatch::getContactId(1); if (empty($contact_id)) { // Last ditch effort $sql = "SELECT MIN(id) FROM civicrm_contact WHERE is_active = 1 AND is_deleted = 0"; $dao = CRM_Core_DAO::executeQuery($sql); $dao->fetch(); $contact_id = $dao->id; } } $params = petitionemail_get_profile_params($key); if (is_null($params)) { return NULL; } $params['created_id'] = $contact_id; $results = civicrm_api3('UFGroup', 'create', $params); if ($results['is_error'] != 0) { $session->setStatus(ts("Error creating the petition email profile group.")); return FALSE; } $value = array_pop($results['values']); $id = $value['id']; CRM_Core_BAO_Setting::setItem($id, $group, $key); return $id; }