本文整理汇总了PHP中CRM_Core_BAO_UFMatch::synchronizeUFMatch方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_UFMatch::synchronizeUFMatch方法的具体用法?PHP CRM_Core_BAO_UFMatch::synchronizeUFMatch怎么用?PHP CRM_Core_BAO_UFMatch::synchronizeUFMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_UFMatch
的用法示例。
在下文中一共展示了CRM_Core_BAO_UFMatch::synchronizeUFMatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: synchronize
/**
* Function for synchronizing cms users with CiviCRM contacts
*
* @param NULL
*
* @return void
*
* @static
* @access public
*/
static function synchronize()
{
//start of schronization code
$config =& CRM_Core_Config::singleton();
CRM_Core_Error::ignoreException();
$db_uf =& self::dbHandle($config);
if ($config->userFramework == 'Drupal') {
$id = 'uid';
$mail = 'mail';
$name = 'name';
} else {
if ($config->userFramework == 'Joomla') {
$id = 'id';
$mail = 'email';
$name = 'name';
} else {
CRM_Core_Error::fatal("CMS user creation not supported for this framework");
}
}
set_time_limit(300);
$sql = "SELECT {$id}, {$mail}, {$name} FROM {$config->userFrameworkUsersTableName} where {$mail} != ''";
$query = $db_uf->query($sql);
$user = new StdClass();
$uf = $config->userFramework;
$contactCount = 0;
$contactCreated = 0;
$contactMatching = 0;
while ($row = $query->fetchRow(DB_FETCHMODE_ASSOC)) {
$user->{$id} = $row[$id];
$user->{$mail} = $row[$mail];
$user->{$name} = $row[$name];
$contactCount++;
if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row[$id], $row[$mail], $uf, 1)) {
$contactCreated++;
} else {
$contactMatching++;
}
if (is_object($match)) {
$match->free();
}
}
$db_uf->disconnect();
//end of schronization code
$status = ts('Synchronize Users to Contacts completed.');
$status .= ' ' . ts('Checked one user record.', array('count' => $contactCount, 'plural' => 'Checked %count user records.'));
if ($contactMatching) {
$status .= ' ' . ts('Found one matching contact record.', array('count' => $contactMatching, 'plural' => 'Found %count matching contact records.'));
}
$status .= ' ' . ts('Created one new contact record.', array('count' => $contactCreated, 'plural' => 'Created %count new contact records.'));
CRM_Core_Session::setStatus($status, true);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
示例2: synchronize
/**
* Function for synchronizing drupal users with CiviCRM contacts
*
* @param NULL
*
* @return void
*
* @static
* @access public
*/
function synchronize()
{
//start of schronization code
$config =& CRM_Core_Config::singleton();
/**
* Update the next line with the correct Drupal database user, password, db_server and db name
* for your Drupal installation.
*/
$db_drupal = DB::connect($config->userFrameworkDSN);
if (DB::isError($db_drupal)) {
die("Cannot connect to UF db via {$dsn}, " . $db_drupal->getMessage());
}
if ($config->userFramework == 'Drupal') {
$id = 'uid';
$mail = 'mail';
} else {
if ($config->userFramework == 'Mambo') {
$id = 'id';
$mail = 'email';
} else {
die("Unknown user framework");
}
}
$sql = "SELECT {$id}, {$mail} FROM {$config->userFrameworkUsersTableName} where {$mail} != ''";
$query = $db_drupal->query($sql);
$user = null;
$uf = 'Drupal';
$contactCount = 0;
$contactCreated = 0;
$contactMatching = 0;
while ($row = $query->fetchRow(DB_FETCHMODE_ASSOC)) {
$contactCount++;
if (CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row[$id], $row[$mail], $uf, 1)) {
$contactCreated++;
} else {
$contactMatching++;
}
}
$db_drupal->disconnect();
//end of schronization code
$status = ts('Synchronize Users to Contacts completed.');
$status .= ' ' . ts('Checked one user record.', array('count' => $contactCount, 'plural' => 'Checked %count user records.'));
if ($contactMatching) {
$status .= ' ' . ts('Found one matching contact record.', array('count' => $contactMatching, 'plural' => 'Found %count matching contact records.'));
}
$status .= ' ' . ts('Created one new contact record.', array('count' => $contactCreated, 'plural' => 'Created %count new contact records.'));
CRM_Core_Session::setStatus($status);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
示例3: contactID
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;
}
示例4: _woocommerce_civicrm_get_cid
/**
* Get contact id for the order's customer.
*
* @param object $order
* Wordpress Order Object
*
* @return false|integer
* > 0: existing contact
* = 0: create new contact
* FALSE: error
*/
function _woocommerce_civicrm_get_cid($order)
{
$user_id = get_current_user_id();
if ($user_id > 0) {
// Logged in user
global $current_user;
get_currentuserinfo();
$match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($current_user, $current_user->ID, $current_user->user_email, 'WordPress', FALSE, 'Individual');
if (!is_object($match)) {
return FALSE;
}
return $match->contact_id;
}
// The customer is anonymous. Look in the CiviCRM contacts table for a
// contact that matches the billing email.
$params = array('email' => $order->billing_email, 'return.contact_id' => TRUE, 'sequential' => 1);
try {
$contact = civicrm_api3('contact', 'get', $params);
} catch (Exception $e) {
return FALSE;
}
// No matches found, so we will need to create a contact.
if (count($contact) == 0) {
return 0;
}
$cid = $contact['values'][0]['id'];
return $cid;
}
示例5: authenticate
/**
* 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
*/
function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
{
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';
$dbpassword = md5($password);
$name = $dbDrupal->escapeSimple($strtolower($name));
$sql = 'SELECT u.* FROM ' . $config->userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '{$name}' AND u.pass = '{$dbpassword}' AND u.status = 1";
$query = $dbDrupal->query($sql);
$user = NULL;
// need to change this to make sure we matched only one row
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;
} else {
//success
if ($loadCMSBootstrap) {
$bootStrapParams = array();
if ($name && $password) {
$bootStrapParams = array('name' => $name, 'pass' => $password);
}
CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
}
return array($contactID, $row['uid'], mt_rand());
}
}
return FALSE;
}
示例6: authenticate
/**
* @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;
}
示例7: synchronizeUsers
/**
* @inheritDoc
*/
public function synchronizeUsers()
{
$config = CRM_Core_Config::singleton();
if (PHP_SAPI != 'cli') {
set_time_limit(300);
}
$id = 'uid';
$mail = 'mail';
$name = 'name';
$result = db_query("SELECT uid, mail, name FROM {users} where mail != ''");
$user = new StdClass();
$uf = $config->userFramework;
$contactCount = 0;
$contactCreated = 0;
$contactMatching = 0;
foreach ($result as $row) {
$user->{$id} = $row->{$id};
$user->{$mail} = $row->{$mail};
$user->{$name} = $row->{$name};
$contactCount++;
if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row->{$id}, $row->{$mail}, $uf, 1, 'Individual', TRUE)) {
$contactCreated++;
} else {
$contactMatching++;
}
if (is_object($match)) {
$match->free();
}
}
return array('contactCount' => $contactCount, 'contactMatching' => $contactMatching, 'contactCreated' => $contactCreated);
}
示例8: wordpress_contact_updated
/**
* Updates a CiviCRM Contact when a WordPress user is updated
*
* @param integer $user_id The numeric ID of the WordPress user
* @return void
*/
public function wordpress_contact_updated($user_id)
{
$this->_debug(array('function' => 'wordpress_contact_updated', 'user_id' => $user_id));
// okay, get user
$user = get_userdata($user_id);
// did we get one?
if ($user) {
// init CiviCRM
if (!civi_wp()->initialize()) {
return;
}
// get user matching file
require_once 'CRM/Core/BAO/UFMatch.php';
// remove CiviCRM and BuddyPress callbacks to prevent recursion
$this->_remove_hooks_bp();
$this->_remove_hooks_civi();
// get the Civi contact object
$civi_contact = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $user->ID, $user->user_email, 'WordPress', null, 'Individual');
// update first name and last name
$this->_update_civi_name($user, $civi_contact);
// optionally update primary email
$this->_update_civi_primary_email($user, $civi_contact);
// optionally update website
$this->_update_civi_website($user, $civi_contact);
// add more built-in WordPress fields here...
// add CiviCRM and BuddyPress callbacks once more
$this->_add_hooks_bp();
$this->_add_hooks_civi();
}
}
示例9: authenticate
/**
* Authenticate the user against the drupal db
*
* @param string $name the user name
* @param string $password the password for the above user name
* @param boolean $loadCMSBootstrap load cms bootstrap?
* @param NULL|string $realPath filename of script
*
* @return mixed false if no auth
* array(
* contactID, ufID, unique string ) if success
* @access public
*/
static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
{
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());
}
$account = $userUid = $userMail = NULL;
if ($loadCMSBootstrap) {
$bootStrapParams = array();
if ($name && $password) {
$bootStrapParams = array('name' => $name, 'pass' => $password);
}
CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
global $user;
if ($user) {
$userUid = $user->uid;
$userMail = $user->mail;
}
} else {
// CRM-8638
// SOAP cannot load drupal bootstrap and hence we do it the old way
// Contact CiviSMTP folks if we run into issues with this :)
$cmsPath = $config->userSystem->cmsRootPath($realPath);
require_once "{$cmsPath}/includes/bootstrap.inc";
require_once "{$cmsPath}/includes/password.inc";
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$name = $dbDrupal->escapeSimple($strtolower($name));
$sql = "\nSELECT u.*\nFROM {$config->userFrameworkUsersTableName} u\nWHERE LOWER(u.name) = '{$name}'\nAND u.status = 1\n";
$query = $dbDrupal->query($sql);
$row = $query->fetchRow(DB_FETCHMODE_ASSOC);
if ($row) {
$fakeDrupalAccount = drupal_anonymous_user();
$fakeDrupalAccount->name = $name;
$fakeDrupalAccount->pass = $row['pass'];
$passwordCheck = user_check_password($password, $fakeDrupalAccount);
if ($passwordCheck) {
$userUid = $row['uid'];
$userMail = $row['mail'];
}
}
}
if ($userUid && $userMail) {
CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $userUid, $userMail, 'Drupal');
$contactID = CRM_Core_BAO_UFMatch::getContactId($userUid);
if (!$contactID) {
return FALSE;
}
return array($contactID, $userUid, mt_rand());
}
return FALSE;
}
示例10: authenticate
/**
* @inheritDoc
*/
public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
{
//@todo this 'PEAR-y' stuff is only required when bookstrap is not being loaded which is rare
// if ever now.
// probably if bootstrap is loaded this call
// CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath); would be
// sufficient to do what this fn does. It does exist as opposed to return which might need some hanky-panky to make
// safe in the unknown situation where authenticate might be called & it is important that
// false is returned
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';
$dbpassword = md5($password);
$name = $dbDrupal->escapeSimple($strtolower($name));
$userFrameworkUsersTableName = $this->getUsersTableName();
$sql = 'SELECT u.* FROM ' . $userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '{$name}' AND u.pass = '{$dbpassword}' AND u.status = 1";
$query = $dbDrupal->query($sql);
$user = NULL;
// need to change this to make sure we matched only one row
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;
} else {
//success
if ($loadCMSBootstrap) {
$bootStrapParams = array();
if ($name && $password) {
$bootStrapParams = array('name' => $name, 'pass' => $password);
}
CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, $realPath);
}
return array($contactID, $row['uid'], mt_rand());
}
}
return FALSE;
}
示例11: synchronizeUsers
/**
* @inheritDoc
*/
public function synchronizeUsers()
{
$config = CRM_Core_Config::singleton();
if (PHP_SAPI != 'cli') {
set_time_limit(300);
}
$users = array();
$users = \Drupal::entityTypeManager()->getStorage('user')->loadByProperties();
$uf = $config->userFramework;
$contactCount = 0;
$contactCreated = 0;
$contactMatching = 0;
foreach ($users as $user) {
$mail = $user->get('mail')->value;
if (empty($mail)) {
continue;
}
$uid = $user->get('uid')->value;
$contactCount++;
if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $uid, $mail, $uf, 1, 'Individual', TRUE)) {
$contactCreated++;
} else {
$contactMatching++;
}
if (is_object($match)) {
$match->free();
}
}
return array('contactCount' => $contactCount, 'contactMatching' => $contactMatching, 'contactCreated' => $contactCreated);
}
示例12: synchronizeUsers
/**
* @inheritDoc
*/
public function synchronizeUsers()
{
$config = CRM_Core_Config::singleton();
if (PHP_SAPI != 'cli') {
set_time_limit(300);
}
$id = 'id';
$mail = 'email';
$name = 'name';
$JUserTable =& JTable::getInstance('User', 'JTable');
$db = $JUserTable->getDbo();
$query = $db->getQuery(TRUE);
$query->select($id . ', ' . $mail . ', ' . $name);
$query->from($JUserTable->getTableName());
$query->where($mail != '');
$db->setQuery($query);
$users = $db->loadObjectList();
$user = new StdClass();
$uf = $config->userFramework;
$contactCount = 0;
$contactCreated = 0;
$contactMatching = 0;
for ($i = 0; $i < count($users); $i++) {
$user->{$id} = $users[$i]->{$id};
$user->{$mail} = $users[$i]->{$mail};
$user->{$name} = $users[$i]->{$name};
$contactCount++;
if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $users[$i]->{$id}, $users[$i]->{$mail}, $uf, 1, 'Individual', TRUE)) {
$contactCreated++;
} else {
$contactMatching++;
}
if (is_object($match)) {
$match->free();
}
}
return array('contactCount' => $contactCount, 'contactMatching' => $contactMatching, 'contactCreated' => $contactCreated);
}
示例13: import_civi_members_to_wordpress
/**
* @return string
* @throws CiviCRM_API3_Exception
*/
static function import_civi_members_to_wordpress()
{
civicrm_wp_initialize();
$return_message = '';
$account_creation_messages = '';
$member_types_to_sync = array();
$rules = self::get_civi_sync_rules();
$array_counter = 0;
foreach ($rules as $key => $value) {
$member_types_to_sync[$array_counter] = $value->civi_mem_type;
$array_counter += 1;
}
//have them pull from the CiviSync rules
$result_current_members = civicrm_api3('Membership', 'get', array('sequential' => 1, 'return' => array("contact_id"), 'membership_type_id' => array('IN' => $member_types_to_sync)));
$current_member_array = array();
foreach ($result_current_members['values'] as $key => $values) {
$current_member_array[] = $values['contact_id'];
}
$result_contacts = civicrm_api3('Contact', 'get', array('sequential' => 1, 'return' => array("first_name", "last_name", "id"), 'id' => array('IN' => $current_member_array)));
if (isset($result_contacts)) {
foreach ($result_contacts['values'] as $key => $values) {
$member_array[$values['id']] = array('email' => '', 'first_name' => $values['first_name'], 'last_name' => $values['last_name']);
}
}
$result_member_emails = civicrm_api3('Email', 'get', array('return' => array("email", "contact_id"), 'contact_id' => array('IN' => $current_member_array), 'is_primary' => 1));
if (isset($result_member_emails)) {
foreach ($result_member_emails['values'] as $key => $values) {
$member_array[$values['contact_id']]['email'] = $values['email'];
}
}
if (isset($member_array)) {
$new_account_count = 0;
//TODO: make this more efficient by filtering out the emails that already exist in Wordpress.
foreach ($member_array as $key => $values) {
//extract the alias part of the email for the new user's username
$email = $values['email'];
$parts = explode("@", $email);
$username = $parts[0];
if (null == username_exists($username) and !empty($email)) {
$password = wp_generate_password(12, true);
$user_id = wp_create_user($username, $password, $email);
if (is_wp_error($user_id)) {
echo 'Error creating user ' . $username . ' / ' . $email . ':<br>' . $user_id->get_error_message();
echo '<br>';
} else {
$account_creation_messages = $account_creation_messages . 'Created account for user ' . $username . ' ID: ' . $user_id . '. <br>';
wp_update_user(array('ID' => $user_id, 'nickname' => $email, 'first_name' => $values['first_name'], 'last_name' => $values['last_name']));
//Update CiviCRM UFMatch record so that the new Wordpress user is appropriately connected to their Contact record in CiviCrm
$user = get_user_by('id', $user_id);
/*TODO: this line is not working. Need to research*/
CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $user->ID, $user->email, 'WordPress');
// Email the user
wp_mail($email, 'Welcome ' . $username . '!', ' Your Password: ' . $password);
//echo 'Welcome ' . $username . '!', ' Your Password: ' . $password . ' sent to ' . $email . '<br>';
$new_account_count += 1;
}
}
}
$return_message = $return_message . 'Total new accounts created: ' . $new_account_count . '<br>' . $account_creation_messages;
}
return $return_message;
}
示例14: authenticate
/**
* 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 = '{$password}' 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;
}
示例15: authenticate
/**
* 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;
}