getUserIntegration(); // Don't do anything if integration has been disabled if ( ! $integrate ) return null; $current = JFactory::getUser(); $app = JFactory::getApplication(); // Replace the ticks that SMF sometimes passes in $data = preg_replace("/^'?(.*?)'?$/", '$1', $data); $change = false; foreach ( $memberNames as $name ) { // Make sure we're updating the right user if ( $current->username == $name ) { $user = $current; } else { $user = JUser::getInstance($name); } // Skip if we don't have a user if ( ! is_object($user) || $user->username != $name ) { continue; } // Find the var that we're changing switch($var) { case 'realName': $change = true; $user->name = $data; break; case 'emailAddress': $change = true; $user->email = $data; break; } // Do we need to save changes to the database if ( $change ) { $user->save(); $session = &JFactory::getSession(); $session->set('user', $user); } } //$app->enqueueMessage("Changing $var to $data"); return true; } $integration['integrate_change_member_data'] = 'j2smf_change_member_data'; /** * Integrate the Joomla and SMF login * * @param string $memberName * @param string $password * @return boolean True if successfully logged into Joomla * @access public * @since 1.0 */ function j2smf_login($memberName, $password) { $j2smf = j2smfBridge::getInstance(); $integrate = $j2smf->getUserIntegration(); // Don't do anything if integration has been disabled if ( ! $integrate ) return true; //global $modSettings, $db_prefix, $cookiename, $language; global $ID_MEMBER, $user_settings, $user_info; // Get the Joomla stuff $user = JFactory::getUser(); $app = JFactory::getApplication(); // Can't do anything without a username if ( ! $memberName ) { return false; } // Change the following code to reflect the login logic that you want or need if ( $user->id ) { // Should we verify the email if ( $j2smf->shouldVerifyEmail() ) { $smail = $j2smf->getSMFMemberEmail($jname); $jmail = $user->email; // If the email addresses don't match, don't do a login if ( $smail != $jmail ) { $message = "Cannot verify user with jid of $jid ( joomla mail '$jmail' smf mail '$smail' )"; $app->enqueueMessage($message); j2smfBridge::logDebug($message); return false; } } // Assume that the current user is our user return true; } // Import the user plugin group require_once(JPATH_BASE.DS.'plugins'.DS.'user'.DS.'joomla.php'); JPluginHelper::importPlugin('user', 'joomla'); // OK, the credentials are authenticated. Lets fire the onLogin event $userdata = array(); $userdata['username'] = $memberName; $userdata['fullname'] = $memberName; $userdata['password_clear'] = 'SMF Authenticated'; $userdata['email'] = $user_settings['emailAddress']; $options = array(); $result = $app->triggerEvent('onLoginUser', array($userdata, $options)); // Get the session object $session =& JFactory::getSession(); $session->close(); } $integration['integrate_login'] = 'j2smf_login'; /** * Integrate the Joomla and SMF logout * * @return boolean True if successfully logged out of Joomla * @access public * @since 1.0 */ function j2smf_logout() { $j2smf = j2smfBridge::getInstance(); $integrate = $j2smf->getUserIntegration(); // Don't do anything if integration has been disabled if ( ! $integrate ) return true; // Check if we should logout the user or not if ( ! $j2smf->shouldEnforceIntegratedLogin() ) return false; // Get a user object from the JApplication $user = &JFactory::getUser($userid); $app = JFactory::getApplication(); // Build the credentials array $parameters = array(); $parameters['username'] = $user->get('username'); $parameters['id'] = $user->get('id'); // Set clientid in the options array if it hasn't been set already $options = array( 'clientid' => array() ); $options['clientid'][] = $app->getClientId(); // Import the user plugin group require_once(JPATH_BASE.DS.'plugins'.DS.'user'.DS.'joomla.php'); JPluginHelper::importPlugin('user', 'joomla'); // OK, the credentials are built. Lets fire the onLogout event $results = $app->triggerEvent('onLogoutUser', array($parameters, $options)); } $integration['integrate_logout'] = 'j2smf_logout'; /** * Verify a user of Joomla against SMF * * This verification routine assumes that users will have identical usernames on both systems. * The actual user ids can be different. Optionally, we can verify the accounts by checking * if the email addresses match. * * @return int Member ID, or NULL if a Member ID cannot be found * @access public * @since 1.0 */ function j2smf_verify_user() { $j2smf = j2smfBridge::getInstance(); $integrate = $j2smf->getUserIntegration(); // Don't do anything if integration has been disabled if ( ! $integrate ) return null; // Get the Joomla user object and the Joomla ID $user = JFactory::getUser(); $app = JFactory::getApplication(); $jname = $user->username; $jid = $user->id; // If verification is successful, we will return an SMF member id with this variable ! $ok = true; // If we don't have a current user, don't bother if ( ! $jid || ! $jname ) { // Destroy the SMF session if we're strictly enforcing integration global $cookiename; if ( $j2smf->shouldEnforceIntegratedLogin() && isset($_COOKIE[$cookiename]) ) { unset($_COOKIE[$cookiename]); } $message = "Cannot verify the user because the Joomla user is a guest"; j2smfBridge::logDebug($message); return null; } $smfid = $j2smf->getSMFMemberID($jname); if ( ! $smfid ) { $message = "Cannot verify the joomla user $jname ( id '$jid' ) with any smf users"; $app->enqueueMessage($message); j2smfBridge::logDebug($message); $ok = false;; } // Should we verify the email if ( $ok && $j2smf->shouldVerifyEmail() ) { $smail = $j2smf->getSMFMemberEmail($jname); $jmail = $user->email; if ( $smail != $jmail ) { $message = "Cannot verify user with jid of $jid ( joomla mail '$jmail' smf mail '$smail' )"; $app->enqueueMessage($message); j2smfBridge::logDebug($message); $ok = false; } } if ( ! $ok ) { // Check if we should log out the current Joomla user if ( $j2smf->shouldEnforceIntegratedLogin() ) { // Call the logout routine j2smf_logout(); } return null; } $message = "Verified user with username $jname ( joomla id '$jid', smf id '$smfid' )"; j2smfBridge::logDebug($message); return $smfid; } $integration['integrate_verify_user'] = 'j2smf_verify_user'; // Include the basic integration script include (dirname(__FILE__).DS.'default.php');