/** * Sync user session * * @param bool $keepalive Keep session alive * * @return number */ function syncSessions($keepalive = false) { $debug = defined('DEBUG_SYSTEM_PLUGIN') ? true : false; if ($debug) { JError::raiseNotice('500', 'XenForo syncSessions called'); } $helper =& JFusionFactory::getHelper($this->getJname()); $params =& JFusionFactory::getParams($this->getJname()); $options = array(); $options['action'] = 'core.login.site'; $expiry = 60 * 60 * 24 * 365; $JUser =& JFactory::getUser(); // Do we have a Joomla persistant session ? if (JPluginHelper::isEnabled('system', 'remember')) { jimport('joomla.utilities.utility'); $hash = JApplicationHelper::getHash('JLOGIN_REMEMBER'); $joomla_persistant_cookie = JRequest::getString($hash, '', 'cookie', JREQUEST_ALLOWRAW | JREQUEST_NOTRIM); } else { $joomla_persistant_cookie = ''; } if (!$JUser->get('guest', true)) { // User logged into Joomla so check for active XenForo session if ($helper->persistantUser()) { // We have a persistant cookie for XenForo // Lets check that the user's match $xenforo_user = (object) $helper->xenUserFromSession(); if (isset($xenforo_user->email) && isset($xenforo_user->username)) { if ($xenforo_user->email == $JUser->email && $xenforo_user->username == $JUser->username) { // Users match, so do nothing. XenForo auto login // will sort out the sessions. } else { // TODO User mismatch, terminate both sessions // for security reasons } } else { // Unknown XenForo user, do nothing } } else { // Do we have an active XenForo session ? if ($helper->sessionCookie()) { // Is this a user session ? $xenuser = $helper->xenUserFromSession(); if (empty($xenuser['user_id'])) { // This is a Xenforo guest session // Log user into XenForo $userinfo = $helper->xenUserFromJUser($JUser); if (isset($userinfo['username'])) { $helper->createSession($userinfo['userid'], $expiry, $userinfo['remember_key']); } else { // No matching user, so do nothing } } else { if (isset($xenuser->email) && isset($xenforo_user->username)) { if ($xenuser->email == $JUser->email && $xenuser->username == $JUser->username) { // Users match, so do nothing. // We are already logged in } else { // TODO User mismatch, terminate both sessions // for security reasons } } else { // Unknown XenForo user, do nothing } } } } } else { // Not logged into Joomla if ($helper->persistantUser()) { // Login to Joomla persistant // First identify the xenforo user $xenuser = (object) $helper->xenUserFromSession(); // Verify that this is a user session if (!empty($xenuser->email) && !empty($xenuser->username)) { // We have a XenForo user session, try to find matching Joomla user $JoomlaUser = JFusionFactory::getUser('joomla_int'); $userinfo = $JoomlaUser->getUser($xenuser); if (!empty($userinfo)) { // We have a valid Joomla user, so create user session. global $JFusionActivePlugin; $JFusionActivePlugin = $this->getJname(); $options['remember'] = true; $status = $JoomlaUser->createSession($userinfo, $options); if ($debug) { JFusionFunction::raiseWarning('500', $status); } // No refresh needed return 0; } else { // No Joomla user, so lets create one. $status = array(); $userinfo = $this->getUser($xenuser); JFusionJplugin::createUser($userinfo, $status, 'joomla_int'); // $jfusion = new JFusionJplugin(); // $result = $jfusion->createUser($userinfo, $status, 'joomla_int'); // Now we have a Joomla user, lets create the Joomla session $JoomlaUser = JFusionFactory::getUser('joomla_int'); $userinfo = $JoomlaUser->getUser($xenuser); if (!empty($userinfo)) { header('Location: http://' . $_SERVER['HTTP_HOST']); exit(0); // We have a valid Joomla user, so create user session.. /*global $JFusionActivePlugin; $JFusionActivePlugin = $this->getJname(); $status = $JoomlaUser->createSession($userinfo, $options); if ($debug) { JFusionFunction::raiseWarning('500',$status); }*/ } return 0; } } // Just create the correct cookie and login } else { // Do we have an active XenForo session ? if ($helper->sessionCookie()) { // Login to Joomla not persistant $xenuser = (object) $helper->xenUserFromSession(); // Verify that this is a user session if (!empty($xenuser->email) && !empty($xenuser->username)) { // We have a XenForo user session, try to find matching Joomla user $JoomlaUser = JFusionFactory::getUser('joomla_int'); $userinfo = $JoomlaUser->getUser($xenuser); if (!empty($userinfo)) { // We have a valid Joomla user, so create user session. global $JFusionActivePlugin; $JFusionActivePlugin = $this->getJname(); $status = $JoomlaUser->createSession($userinfo, $options); if ($debug) { JFusionFunction::raiseWarning('500', $status); } // No refresh needed return 0; } else { // No Joomla user exists yet, so create one. $status = array(); $userinfo = $this->getUser($xenuser); JFusionJplugin::createUser($userinfo, $status, 'joomla_int'); // $jfusion = new JFusionJplugin(); // $result = $jfusion->createUser($userinfo, $status, 'joomla_int'); // Now we have a Joomla user, lets create the Joomla session $JoomlaUser = JFusionFactory::getUser('joomla_int'); $userinfo = $JoomlaUser->getUser($xenuser); if (!empty($userinfo)) { header('Location: http://' . $_SERVER['HTTP_HOST']); exit(0); // We have a valid Joomla user, so create user session. /*global $JFusionActivePlugin; $JFusionActivePlugin = $this->getJname(); $status = $JoomlaUser->createSession($userinfo, $options); if ($debug) { JFusionFunction::raiseWarning('500',$status); }*/ } return 0; } } } else { // Not logged into either app, do nothing } } } return 0; }
public static function create_jfusion_user(&$user, $newuser) { include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfusion' . DS . 'models' . DS . 'model.jfusion.php'; include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfusion' . DS . 'models' . DS . 'model.factory.php'; $options = array('entry_url' => JURI::root() . 'index.php?option=com_user&task=login', 'silent' => true); $slaves = JFusionFunction::getPlugins(); foreach ($slaves as $slave) { if ($slave->dual_login == 1) { $JFusionSlave = JFusionFactory::getUser($slave->name); $status = array(); $slaveUser = $JFusionSlave->getUser($user); if (empty($slaveUser)) { if ($slave->name == 'vbulletin') { $slaveUser->password_clear = $user->password; $slaveUser->password = $user->password; $slaveUser->userid = $user->id; $slaveUser->username = $user->username; $slaveUser->email = $user->email; $JFusionSlave->createUser($slaveUser, $status); } else { $JFusionSlave->createUser($user, $status); } $slaveUser = $JFusionSlave->getUser($user); } if ($newuser == false) { $user->password_clear = $user->password; $slaveUser->password_clear = $user->password_clear; $JFusionSlave->updatePassword($user, $slaveUser, $status); } else { $user->password_clear = $user->password_clear; $slaveUser->password_clear = $user->password_clear; } $JFusionSlave->createSession($slaveUser, $options); } } }
/** * Create the user authorisation record for XenForum * * @param object $userinfo User info * * @return stdClass */ private function createAuthObject($userinfo) { $authRecord = new stdClass(); $authRecord->user_id = $userinfo->user_id; $authRecord->remember_key = $this->generateRandomString(40); if (!empty($userinfo->password_clear)) { //require_once JPATH_ADMINISTRATOR . '/components/com_jfusion/models/model.factory.php'; $JFusionAuth = JFusionFactory::getAuth($this->getJname()); // We have the original password, so use the xenforo encoding $authRecord->scheme_class = 'XenForo_Authentication_Core'; $userinfo->scheme_class = $authRecord->scheme_class; $userinfo->hashFunc = 'sha256'; $userinfo->password_salt = $this->generateRandomString(64); /* {hash, salt, hashFunc) */ $data['hash'] = $JFusionAuth->generateEncryptedPassword($userinfo); $data['hashFunc'] = $userinfo->hashFunc; $data['salt'] = $userinfo->password_salt; } else { /* {hash, salt) */ // No original password, so use the Joomla class for authentication $authRecord->scheme_class = 'JoomlaBridge_Authentication_Joomla'; $data['hash'] = $userinfo->password; $data['salt'] = $userinfo->password_salt; } $authRecord->data = serialize($data); return $authRecord; }
/** * Get an usergroup element * * @param string $name Name of element * @param string $value Value of element * @param string $node Node of element * @param string $control_name Name of controler * * @return string html */ function usergroup($name, $value, $node, $control_name) { $jname = $this->getJname(); // Get the master plugin to be throughout $master = JFusionFunction::getMaster(); $advanced = 0; // Detect is value is a serialized array if (substr($value, 0, 2) == 'a:') { $value = unserialize($value); // Use advanced only if this plugin is not set as master if ($master->name != $this->getJname()) { $advanced = 1; } } if (JFusionFunction::validPlugin($this->getJname())) { $usergroups = $this->getUsergroupList(); foreach ($usergroups as $group) { $g[] = $group->name; } $comma_separated = implode(",", $g); $simple_value = $value; if (is_array($simple_value)) { $simple_value = $comma_separated; } if (!empty($usergroups)) { $simple_usergroup = "<table style=\"width:100%; border:0\">"; $simple_usergroup .= '<tr><td>' . JText::_('DEFAULT_USERGROUP') . '</td><td><input type="text" name="' . $control_name . '[' . $name . ']" value="' . $simple_value . '" class="inputbox" /></td></tr>'; $simple_usergroup .= "</table>"; } else { $simple_usergroup = ''; } } else { return JText::_('SAVE_CONFIG_FIRST'); } // Check to see if current plugin is a slave $db =& JFactory::getDBO(); $query = 'SELECT slave FROM #__jfusion WHERE name = ' . $db->Quote($jname); $db->setQuery($query); $slave = $db->loadResult(); $list_box = '<select onchange="usergroupSelect(this.selectedIndex);">'; if ($advanced == 1) { $list_box .= '<option value="0" selected="selected">Simple</option>'; } else { $list_box .= '<option value="0">Simple</option>'; } if ($slave == 1) { // Allow usergroup sync if ($advanced == 1) { $list_box .= '<option selected="selected" value="1">Avanced</option>'; } else { $list_box .= '<option value="1">Avanced</option>'; } // Prepare the advanced options $JFusionMaster = JFusionFactory::getAdmin($master->name); $master_usergroups = $JFusionMaster->getUsergroupList(); $advanced_usergroup = "<table class=\"usergroups\">"; if ($advanced == 1) { foreach ($master_usergroups as $master_usergroup) { $advanced_usergroup .= "<tr><td>" . $master_usergroup->name . '</td>'; $advanced_usergroup .= '<td><input type="text" name="' . $control_name . '[' . $name . '][' . $master_usergroup->id . ']" value="' . $value[$master_usergroup->id] . '" class="inputbox" /></td></tr>'; } } else { foreach ($master_usergroups as $master_usergroup) { $advanced_usergroup .= "<tr><td>" . $master_usergroup->name . '</td>'; $advanced_usergroup .= '<td><input type="text" name="' . $control_name . '[' . $name . '][' . $master_usergroup->id . ']" value="' . $comma_separated . '" class="inputbox" /></td></tr>'; } } $advanced_usergroup .= "</table>"; } else { $advanced_usergroup = ''; } $list_box .= '</select>'; ?> <script Language="JavaScript"> function usergroupSelect(option) { var myArray = new Array(); myArray[0] = '<?php echo $simple_usergroup; ?> '; myArray[1] = '<?php echo $advanced_usergroup; ?> '; document.getElementById("JFusionUsergroup").innerHTML = myArray[option]; } </script> <?php if ($advanced == 1) { return JText::_('USERGROUP') . ' ' . JText::_('MODE') . ': ' . $list_box . '<br/><div id="JFusionUsergroup">' . $advanced_usergroup . '</div>'; } else { return JText::_('USERGROUP') . ' ' . JText::_('MODE') . ': ' . $list_box . '<br/><div id="JFusionUsergroup">' . $simple_usergroup . '</div>'; } }
/** * Get the number of on-line members * * @return int */ function getNumberOnlineMembers() { // Get a unix time from 5 mintues ago date_default_timezone_set('UTC'); $active = strtotime("-5 minutes", time()); $db =& JFusionFactory::getDatabase($this->getJname()); $query = "SELECT COUNT(DISTINCT(session_user_id)) FROM #__sessions WHERE session_viewonline = 1 AND session_user_id != 1 AND session_time > {$active}"; $db->setQuery($query); $result = $db->loadResult(); return $result; }