/** * validate the elements data against the rule * @param string data to check * @param object element * @param int plugin sequence ref * @return bol true if validation passes, false if fails */ function validate($data, &$element, $c) { $params =& $this->getParams(); $ornot = $params->get('userexists_or_not'); $condition = $params->get('userexists-validation_condition'); $condition = $condition[$c]; if ($condition !== '') { if (@eval($condition)) { return true; } } $ornot = $ornot[$c]; jimport('joomla.user.helper'); $id = 0; if (!($id = JUserHelper::getUserId($data))) { if ($ornot == 'fail_if_exists') { return true; } } else { if ($ornot == 'fail_if_not_exists') { return true; } } return false; }
/** * Returns the global KunenaUser object, only creating it if it doesn't already exist. * * @param mixed $identifier The user to load - Can be an integer or string - If string, it is converted to ID automatically. * @param bool $reload Reload user from database. * * @return KunenaUser */ public static function get($identifier = null, $reload = false) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if ($identifier === null || $identifier === false) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return self::$_me; } if ($identifier instanceof KunenaUser) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $identifier; } // Find the user id if ($identifier instanceof JUser) { $id = (int) $identifier->id; } elseif ((string) (int) $identifier === (string) $identifier) { // Ignore imported users, which haven't been mapped to Joomla (id<0). $id = (int) max($identifier, 0); } else { // Slow, don't use usernames! $id = (int) JUserHelper::getUserId((string) $identifier); } // Always return fresh user if id is anonymous/not found if ($id === 0) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return new KunenaUser($id); } elseif ($reload || empty(self::$_instances[$id])) { self::$_instances[$id] = new KunenaUser($id); // Preload avatar if configured. $avatars = KunenaFactory::getAvatarIntegration(); $avatars->load(array($id)); } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return self::$_instances[$id]; }
/** * getChannels * * @param string $author Param * * @return array */ public function getChannels($author) { $channels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel'); $channels->set('published', true); $channels->set('scope', 'S'); $channels->set('filter_order', 'ordering'); $channels->set('filter_order_Dir', 'ASC'); $list = $channels->getItemList(true); if (!empty($author)) { $user_id = JUserHelper::getUserId($author); if ($user_id) { $userChannels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel'); $userChannels->set('published', true); $userChannels->set('scope', 'U'); $userChannels->set('created_by', $user_id); $userChannels->set('filter_order', 'ordering'); $userChannels->set('filter_order_Dir', 'ASC'); $userList = $userChannels->getItemList(true); $list = array_merge($list, $userList); } } $channels = array(); foreach ($list as $channel) { $channels[$channel->id] = self::createChannel($channel); } $logger = AutotweetLogger::getInstance(); $channels_ids = array_keys($channels); $logger->log(JLog::INFO, 'ChannelFactory getChannels user=' . $author, $channels_ids); return $channels; }
/** * @inheritDoc */ public function createUser(&$params, $mail) { $baseDir = JPATH_SITE; require_once $baseDir . '/components/com_users/models/registration.php'; $userParams = JComponentHelper::getParams('com_users'); $model = new UsersModelRegistration(); $ufID = NULL; // get the default usertype $userType = $userParams->get('new_usertype'); if (!$userType) { $userType = 2; } if (isset($params['name'])) { $fullname = trim($params['name']); } elseif (isset($params['contactID'])) { $fullname = trim(CRM_Contact_BAO_Contact::displayName($params['contactID'])); } else { $fullname = trim($params['cms_name']); } // Prepare the values for a new Joomla user. $values = array(); $values['name'] = $fullname; $values['username'] = trim($params['cms_name']); $values['password1'] = $values['password2'] = $params['cms_pass']; $values['email1'] = $values['email2'] = trim($params[$mail]); $lang = JFactory::getLanguage(); $lang->load('com_users', $baseDir); $register = $model->register($values); $ufID = JUserHelper::getUserId($values['username']); return $ufID; }
/** * Returns the global KunenaUser object, only creating it if it doesn't already exist. * * @access public * @param int $id The user to load - Can be an integer or string - If string, it is converted to ID automatically. * @return JUser The User object. * @since 1.6 */ public static function getInstance($identifier = null, $reset = false) { $c = __CLASS__; if ($identifier instanceof KunenaUser) { return $identifier; } if ($identifier === null || $identifier === false) { $identifier = JFactory::getUser(); } // Find the user id if ($identifier instanceof JUser) { $id = intval($identifier->id); } else { if (is_numeric($identifier)) { $id = intval($identifier); } else { jimport('joomla.user.helper'); $id = intval(JUserHelper::getUserId((string) $identifier)); } } if ($id < 1) { return new $c(); } if (!$reset && empty(self::$_instances[$id])) { self::$_instances[$id] = new $c($id); } return self::$_instances[$id]; }
/** * Returns the global KunenaUserHelper object, only creating it if it doesn't already exist. * * @access public * @param int $id The user to load - Can be an integer or string - If string, it is converted to ID automatically. * @return JUser The User object. * @since 1.6 */ public static function get($identifier = null, $reload = false) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if ($identifier === null || $identifier === false) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return self::$_me; } if ($identifier instanceof KunenaUser) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $identifier; } // Find the user id if ($identifier instanceof JUser) { $id = intval($identifier->id); } else { if (is_numeric($identifier)) { $id = intval($identifier); } else { jimport('joomla.user.helper'); $id = intval(JUserHelper::getUserId((string) $identifier)); } } // Always return fresh user if id is anonymous/not found if ($id === 0) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return new KunenaUser($id); } else { if ($reload || empty(self::$_instances[$id])) { self::$_instances[$id] = new KunenaUser($id); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return self::$_instances[$id]; }
/** * This method will return a user object * * If options['autoregister'] is true, if the user doesn't exist yet he will be created * * @param array $user Holds the user data. * @param array $options Array holding options (remember, autoregister, group). * * @return object A JUser object * @since 1.5 */ protected function _getUser($user, $options = array()) { $instance = JUser::getInstance(); if ($id = intval(JUserHelper::getUserId($user['username']))) { $instance->load($id); return $instance; } //TODO : move this out of the plugin jimport('joomla.application.component.helper'); $config = JComponentHelper::getParams('com_users'); // Default to Registered. $defaultUserGroup = $config->get('new_usertype', 2); $acl = JFactory::getACL(); $instance->set('id', 0); $instance->set('name', $user['fullname']); $instance->set('username', $user['username']); $instance->set('password_clear', $user['password_clear']); $instance->set('email', $user['email']); // Result should contain an email (check) $instance->set('usertype', 'deprecated'); $instance->set('groups', array($defaultUserGroup)); //If autoregister is set let's register the user $autoregister = isset($options['autoregister']) ? $options['autoregister'] : $this->params->get('autoregister', 1); if ($autoregister) { if (!$instance->save()) { return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError()); } } else { // No existing user and autoregister off, this is a temporary user. $instance->set('tmp_user', true); } return $instance; }
function display($tpl = null) { $user = User::getRoot(); // If this is an auth_link account update, carry on, otherwise raise an error if (!is_object($user) || !array_key_exists('auth_link_id', $user) || !is_numeric($user->get('username')) || !$user->get('username') < 0) { App::abort('405', 'Method not allowed'); return; } // Get and add the js and extra css to the page \Hubzero\Document\Assets::addComponentStylesheet('com_users', 'link.css'); \Hubzero\Document\Assets::addComponentStylesheet('com_users', 'providers.css'); \Hubzero\Document\Assets::addComponentScript('com_users', 'link'); // Import a few things jimport('joomla.user.helper'); // Look up a few things $hzal = \Hubzero\Auth\Link::find_by_id($user->get("auth_link_id")); $hzad = \Hubzero\Auth\Domain::find_by_id($hzal->auth_domain_id); $plugins = Plugin::byType('authentication'); // Get the display name for the current plugin being used Plugin::import('authentication', $hzad->authenticator); $plugin = Plugin::byType('authentication', $hzad->authenticator); $pparams = new \Hubzero\Config\Registry($plugin->params); $refl = new ReflectionClass("plgAuthentication{$plugin->name}"); $display_name = $pparams->get('display_name', $refl->hasMethod('onGetLinkDescription') ? $refl->getMethod('onGetLinkDescription')->invoke(NULL) : ucfirst($plugin->name)); // Look for conflicts - first check in the hub accounts $profile_conflicts = \Hubzero\User\Profile\Helper::find_by_email($hzal->email); // Now check the auth_link table $link_conflicts = \Hubzero\Auth\Link::find_by_email($hzal->email, array($hzad->id)); $conflict = array(); if ($profile_conflicts) { foreach ($profile_conflicts as $p) { $user_id = JUserHelper::getUserId($p); $juser = User::getInstance($user_id); $auth_link = \Hubzero\Auth\Link::find_by_user_id($juser->id); $dname = is_object($auth_link) && $auth_link->auth_domain_name ? $auth_link->auth_domain_name : 'hubzero'; $conflict[] = array("auth_domain_name" => $dname, "name" => $juser->name, "email" => $juser->email); } } if ($link_conflicts) { foreach ($link_conflicts as $l) { $juser = User::getInstance($l['user_id']); $conflict[] = array("auth_domain_name" => $l['auth_domain_name'], "name" => $juser->name, "email" => $l['email']); } } // Make sure we don't somehow have any duplicate conflicts $conflict = array_map("unserialize", array_unique(array_map("serialize", $conflict))); // @TODO: Could also check for high probability of name matches??? // Get the site name $sitename = Config::get('sitename'); // Assign variables to the view $this->assign('hzal', $hzal); $this->assign('hzad', $hzad); $this->assign('plugins', $plugins); $this->assign('display_name', $display_name); $this->assign('conflict', $conflict); $this->assign('sitename', $sitename); $this->assignref('juser', $user); parent::display($tpl); }
/** * Validate the elements data against the rule * * @param string $data to check * @param object &$elementModel element Model * @param int $pluginc plugin sequence ref * @param int $repeatCounter repeat group counter * * @return bool true if validation passes, false if fails */ public function validate($data, &$elementModel, $pluginc, $repeatCounter) { $params = $this->getParams(); $pluginc = trim((string) $pluginc); // As ornot is a radio button it gets json encoded/decoded as an object $ornot = (object) $params->get('userexists_or_not'); $ornot = isset($ornot->{$pluginc}) ? $ornot->{$pluginc} : 'fail_if_exists'; $user = JFactory::getUser(); jimport('joomla.user.helper'); $result = JUserHelper::getUserId($data); if ($user->get('guest')) { if (!$result) { if ($ornot == 'fail_if_exists') { return true; } } else { if ($ornot == 'fail_if_not_exists') { return true; } } return false; } else { if (!$result) { if ($ornot == 'fail_if_exists') { return true; } } else { $user_field = (array) $params->get('userexists_user_field', array()); $user_field = $user_field[$pluginc]; $user_id = 0; if ((int) $user_field !== 0) { $user_elementModel = FabrikWorker::getPluginManager()->getElementPlugin($user_field); $user_fullName = $user_elementModel->getFullName(false, true, false); $user_field = $user_elementModel->getFullName(false, false, false); } if (!empty($user_field)) { // $$$ the array thing needs fixing, for now just grab 0 $formdata = $elementModel->getForm()->_formData; $user_id = JArrayHelper::getValue($formdata, $user_fullName . '_raw', JArrayHelper::getValue($formdata, $user_fullName, '')); if (is_array($user_id)) { $user_id = JArrayHelper::getValue($user_id, 0, ''); } } if ($user_id != 0) { if ($result == $user_id) { return $ornot == 'fail_if_exists' ? true : false; } return false; } else { // The connected user is editing his own data if ($result == $user->get('id')) { return $ornot == 'fail_if_exists' ? true : false; } return false; } } return false; } }
/** * Validate the elements data against the rule * * @param string $data To check * @param int $repeatCounter Repeat group counter * * @return bool true if validation passes, false if fails */ public function validate($data, $repeatCounter) { $params = $this->getParams(); $elementModel = $this->elementModel; // As ornot is a radio button it gets json encoded/decoded as an object $orNot = $params->get('userexists_or_not', 'fail_if_exists'); jimport('joomla.user.helper'); $result = JUserHelper::getUserId($data); if ($this->user->get('guest')) { if (!$result) { if ($orNot == 'fail_if_exists') { return true; } } else { if ($orNot == 'fail_if_not_exists') { return true; } } return false; } else { if (!$result) { if ($orNot == 'fail_if_exists') { return true; } } else { $userField = $params->get('userexists_user_field'); $userId = 0; if ((int) $userField !== 0) { $userElementModel = FabrikWorker::getPluginManager()->getElementPlugin($userField); $userFullName = $userElementModel->getFullName(true, false); $userField = $userElementModel->getFullName(false, false); } if (!empty($userField)) { // $$$ the array thing needs fixing, for now just grab 0 $formData = $elementModel->getForm()->formData; $userId = FArrayHelper::getValue($formData, $userFullName . '_raw', FArrayHelper::getValue($formData, $userFullName, '')); if (is_array($userId)) { $userId = FArrayHelper::getValue($userId, 0, ''); } } if ($userId != 0) { if ($result == $userId) { return $orNot == 'fail_if_exists' ? true : false; } return false; } else { // The connected user is editing his own data if ($result == $this->user->get('id')) { return $orNot == 'fail_if_exists' ? true : false; } return false; } } return false; } }
static function activate_joomla_user($username) { $user_id = JUserHelper::getUserId($username); $user = JFactory::getUser($user_id); $user->set('block', '0'); if (!$user->save()) { return false; } return true; }
static function send_registration_email($username, $password) { $config = JFactory::getConfig(); $params = JComponentHelper::getParams('com_users'); $useractivation = $params->get('useractivation'); $sendpassword = $params->get('sendpassword', 1); JPlugin::loadLanguage('com_users', JPATH_SITE); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::base(); $user_id = JUserHelper::getUserId($username); $user = JFactory::getUser($user_id); $data['username'] = $username; $data['password_clear'] = $password; $data['name'] = $user->name; $data['email'] = $user->email; $data['activation'] = $user->activation; // Handle account activation/confirmation emails. if ($useractivation == 2) { // Set the link to confirm the user email. $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false); $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']); } } else { if ($useractivation == 1) { // Set the link to activate the user account. $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false); $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']); } } else { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']); } } } // Send the registration email. $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); }
/** * Get user by username * * @param string $username The username of the user to load * * @return \JUser|null A user object if it exists, null if it doesn't */ public function getUserByUsername($username) { try { $id = \JUserHelper::getUserId($username); } catch (\Exception $e) { $id = null; } if (empty($id)) { return null; } return $this->getUser($id); }
public function onBeforeBrowse() { // If we have a username/password pair, log in the user if he's a guest $username = $this->input->getString('username', ''); $password = $this->input->getString('password', ''); $user = JFactory::getUser(); if ($user->guest && !empty($username) && !empty($password)) { JLoader::import('joomla.user.authentication'); $credentials = array('username' => $username, 'password' => $password); $app = JFactory::getApplication(); $options = array('remember' => false); $authenticate = JAuthentication::getInstance(); $response = $authenticate->authenticate($credentials, $options); if ($response->status == JAuthentication::STATUS_SUCCESS) { JPluginHelper::importPlugin('user'); $results = $app->triggerEvent('onLoginUser', array((array) $response, $options)); JLoader::import('joomla.user.helper'); $userid = JUserHelper::getUserId($response->username); $user = JFactory::getUser($userid); $parameters['username'] = $user->get('username'); $parameters['id'] = $user->get('id'); } } // If we still have a guest user, show the login page if ($user->guest) { // Show login page $juri = JURI::getInstance(); $myURI = base64_encode($juri->toString()); $com = version_compare(JVERSION, '1.6.0', 'ge') ? 'users' : 'user'; JFactory::getApplication()->redirect(JURI::base() . 'index.php?option=com_' . $com . '&view=login&return=' . $myURI); return false; } // Does the user have core.manage access or belongs to SA group? $isAdmin = $user->authorise('core.manage', 'com_akeebasubs'); if ($this->input->getInt('allUsers', 0) && $isAdmin) { $this->getThisModel()->user_id(null); } else { $this->getThisModel()->user_id(JFactory::getUser()->id); } if ($this->input->getInt('allStates', 0) && $isAdmin) { $this->getThisModel()->paystate(null); } else { $this->getThisModel()->paystate('C,P'); } // Let me cheat. If the request doesn't specify how many records to show, show them all! if ($this->input->getCmd('format', 'html') != 'html') { if (!$this->input->getInt('limit', 0) && !$this->input->getInt('limitstart', 0)) { $this->getThisModel()->limit(0); $this->getThisModel()->limitstart(0); } } return true; }
/** * Short description for 'addmanager' * * @return void */ public function addTask() { // Check for request forgeries Request::checkToken(); // Incoming member ID $id = Request::getInt('id', 0); if (!$id) { $this->setError(Lang::txt('COM_COURSES_ERROR_NO_ID')); $this->displayTask(); return; } // Load the profile $course = \Components\Courses\Models\Course::getInstance($id); $managers = $course->managers(); //get('managers'); // Incoming host $m = Request::getVar('usernames', '', 'post'); $mbrs = explode(',', $m); jimport('joomla.user.helper'); $users = array(); foreach ($mbrs as $mbr) { // Retrieve user's account info $mbr = trim($mbr); // User ID if (is_numeric($mbr)) { // Make sure the user exists $user = User::getInstance($mbr); if (is_object($user) && $user->get('username')) { $uid = $mbr; } } else { $uid = \JUserHelper::getUserId($mbr); } // Ensure we found an account if ($uid) { // Loop through existing members and make sure the user isn't already a member if (isset($managers[$uid])) { $this->setError(Lang::txt('COM_COURSES_ERROR_ALREADY_MANAGER', $mbr)); continue; } // They user is not already a member, so we can go ahead and add them $users[] = $uid; } else { $this->setError(Lang::txt('COM_COURSES_ERROR_USER_NOTFOUND') . ' ' . $mbr); } } // Add users $course->add($users, Request::getInt('role', 0)); // Push through to the hosts view $this->displayTask($course); }
/** * Removes the flag for logging out/in inside Akeeba Subscription user table */ public function onUserLogin($response, $options) { $userid = JUserHelper::getUserId($response['username']); $juser = JFactory::getUser($userid); $user = F0FModel::getTmpInstance('Users', 'AkeebasubsModel')->getTable(); $user->load(array('user_id' => $juser->id)); // Mhm... the user was not found inside Akeeba Subscription, better stop here if (!$user->akeebasubs_user_id) { return true; } $bind['needs_logout'] = 0; $user->save($bind); return true; }
public static function get_exist_username($username) { $nameexists = true; $index = 0; $userName = $username; while ($nameexists == true) { if (JUserHelper::getUserId($userName) != 0) { $index++; $userName = $username . $index; } else { $nameexists = false; } } return $userName; }
function display($tpl = null) { $doc = JFactory::getDocument(); $my = JXFactory::getUser(); $doc->setTitle(JText::_('COM_COMMUNITY_INBOX_PRIVATE_MESSAGING')); $this->addPathway(JText::_('COM_COMMUNITY_INBOX')); // Add file attachment library $doc->addScript(JURI::root() . 'media/uploader/fileuploader.js'); $doc->addStyleSheet(JURI::root() . 'media/uploader/fileuploader.css'); //JXModule::addBuffer('right', '<br /><h4>Side bar stuff goes here</h4>'); $messagingModel = MessagingFactory::getModel('inbox'); $msg =& $messagingModel->getInbox(); // Add small avatar to each image if (!empty($msg)) { foreach ($msg as $key => $val) { // based on the grouped message parent. check the unread message // count for this user. $filter['parent'] = $val->parent; $filter['user_id'] = $my->id; $unRead = $messagingModel->countUnRead($filter); $msg[$key]->unRead = $unRead; } } $data = new stdClass(); $data->msg = $msg; $newFilter['user_id'] = $my->id; $data->inbox = $messagingModel->countUnRead($newFilter); $data->pagination =& $messagingModel->getPagination(); for ($i = 0; $i < count($data->msg); $i++) { $row =& $data->msg[$i]; $user = JXFactory::getUser($row->from); $row->avatar = $user->getThumbAvatarURL(); $row->isUnread = $row->unRead > 0 ? true : false; $row->from_name = $user->name; $row->reply_count = $messagingModel->countReplies($row->parent); $row->recipients = $messagingModel->getParticipantsID($row->id, $my->id); $row->recipientsCount = count($row->recipients); } $to = JRequest::getString('to', null, 'GET'); if ($to) { $toUser = JXFactory::getUser(JUserHelper::getUserId($to)); } $this->assignRef('my', $my); $this->assignRef('toUser', $toUser); $this->assignRef('messages', $data->msg); $this->assign('totalMessages', $messagingModel->getUserInboxCount()); parent::display($tpl); }
/** * Add a user to the manager list * * @return void */ public function addTask() { // Check for request forgeries Request::checkToken(); // Incoming member ID $id = Request::getInt('offering', 0); if (!$id) { $this->setError(Lang::txt('COURSES_NO_ID')); $this->displayTask(); return; } $section = Request::getInt('section', 0); $role_id = Request::getInt('role', 0); // Load the profile $model = \Components\Courses\Models\Offering::getInstance($id); if ($section) { $model->section($section); } $managers = $model->managers(array('student' => 0, 'section_id' => array(0, $section), 'offering_id' => array(0, $id))); // Incoming host $m = Request::getVar('usernames', '', 'post'); $mbrs = explode(',', $m); jimport('joomla.user.helper'); $users = array(); foreach ($mbrs as $mbr) { // Retrieve user's account info $mbr = trim($mbr); $uid = \JUserHelper::getUserId($mbr); // Ensure we found an account if ($uid) { // Loop through existing members and make sure the user isn't already a member if (isset($managers[$uid])) { $this->setError(Lang::txt('COM_COURSES_ERROR_ALREADY_MANAGER', $mbr)); continue; } // They user is not already a member, so we can go ahead and add them $users[] = $uid; } else { $this->setError(Lang::txt('COM_COURSES_ERROR_USER_NOTFOUND') . ' ' . $mbr); } } if (count($users) > 0) { $model->add($users, $role_id); } // Push through to the hosts view $this->displayTask($model); }
function display($tpl = null) { $name = JRequest::getString('user'); $userId = JUserHelper::getUserId($name); $user = JXFactory::getUser($userId); $lastStatus = $user->getStatus(); $vals['name'] = $user->get('name'); $vals['username'] = $user->get('username'); $vals['designation'] = $user->get('designation'); $vals['about_me'] = $user->getParam('about_me'); $vals['skills'] = $user->get('skills'); $vals['avatar'] = $user->getAvatarURL(); // wrapper $results['profile'] = $vals; echo json_encode($results); exit; }
/** * validate the elements data against the rule * @param string data to check * @param object element * @param int plugin sequence ref * @param int repeat group count * @return bol true if validation passes, false if fails */ function validate($data, &$element, $c, $repeat_count = 0) { $params =& $this->getParams(); $ornot = $params->get('userexists_or_not', '_default', 'array', $c); $ornot = is_array($ornot) ? JArrayHelper::getValue($ornot, $c, 'fail_if_exists') : 'fail_if_exists'; jimport('joomla.user.helper'); $user = JFactory::getUser(); if ($user->get('guest')) { $id = 0; if (!($id = JUserHelper::getUserId($data))) { if ($ornot == 'fail_if_exists') { return true; } } else { if ($ornot == 'fail_if_not_exists') { return true; } } return false; } else { if (JUserHelper::getUserId($data) == $user->get('id')) { if ($ornot == 'fail_if_exists') { return true; } else { return false; } } else { if (JUserHelper::getUserId($data) == 0) { // The username does not exist if ($ornot == 'fail_if_exists') { return true; } else { return false; } } else { // The username exists for a different user if ($ornot == 'fail_if_exists') { return false; } else { return true; } } } } }
public function import() { $this->start = $this->state->get('start', 0); $sugarTableConnection = new mysqli(".", "root", "2bornot2b", "admin_mem99"); if (!$sugarTableConnection) { $this->error = 'could not connect to db.'; } $sql = ' SELECT c.*,cc.*, ea.email_address FROM admin_mem99.s4kpe_coach c ' . ' LEFT JOIN admin_mem99.s4kpe_coach_cstm cc on cc.id_c = c.id ' . ' LEFT JOIN admin_mem99.email_addr_bean_rel eabr on eabr.bean_id = c.id and bean_module = "s4kpe_coach" ' . ' LEFT JOIN admin_mem99.email_addresses ea on ea.id = eabr.email_address_id ' . ' LIMIT ' . $this->start . ',200'; $resource = mysqli_query($sugarTableConnection, $sql); if ($resource->num_rows > 0) { $this->start = $this->start + $resource->num_rows; while ($row = $resource->fetch_object()) { $coachTable = new Sp4kTablesBase('#__sp4k_coach_items'); $coach = new stdClass(); $coach->created = strtotime($row->date_entered); $coach->state = !$row->deleted; $coach->status = ''; $coach->title = $row->salutation; $coach->name = $row->first_name . ' ' . $row->last_name; $coach->phone = $row->phone_mobile; $coach->driving = $row->driving_c; $coach->city = $row->city_c; $coach->kitholder = $row->kitholder_c; $coach->role = $row->coachinglevel_c; $coach->reserve = $row->subsbench_c; $coach->dotw1 = $row->monday_c; $coach->dotw2 = 0; $coach->dotw3 = 0; $coach->dotw4 = 0; $coach->dotw5 = 0; $coach->dotw6 = $row->saturday_c; $coach->dotw7 = $row->sunday_c; $coach->sugar_coach_id = $row->id; if (isset($row->email_address) && $row->email_address != '' && trim($row->first_name . ' ' . $row->last_name) != '' && !JUserHelper::getUserId(strtolower($row->email_address))) { $coach->juser_id = $this->addJoomlaUser(strtolower($row->email_address), trim($row->first_name . ' ' . $row->last_name), strtolower($row->email_address), JUserHelper::genRandomPassword()); } else { $coach->juser_id = 0; } $coachTable->save($coach); } } else { $this->continue = false; } }
/** * validate the elements data against the rule * @param string data to check * @param object element * @param int plugin sequence ref * @return bol true if validation passes, false if fails */ function validate($data, &$element, $c) { $params = $this->getParams(); $c = trim((string) $c); //as ornot is a radio button it gets json encoded/decoded as an object $ornot = (object) $params->get('userexists_or_not'); $ornot = isset($ornot->{$c}) ? $ornot->{$c} : 'fail_if_exists'; jimport('joomla.user.helper'); $id = 0; if (!($id = JUserHelper::getUserId($data))) { if ($ornot == 'fail_if_exists') { return true; } } else { if ($ornot == 'fail_if_not_exists') { return true; } } return false; }
public function import() { $this->start = $this->state->get('start', 0); $sugarTableConnection = new mysqli(".", "root", "2bornot2b", "admin_mem99"); if (!$sugarTableConnection) { $this->error = 'could not connect to db.'; } $selectSugarParentsTableSql = ' SELECT p.*,emails.email_address ' . ' FROM admin_mem99.s4kpe_parent AS p ' . ' LEFT JOIN `email_addr_bean_rel` eabr on eabr.bean_module = "s4kpe_parent" and eabr.bean_id = p.id and primary_address = 1 ' . ' LEFT JOIN `email_addresses` emails on emails.id = eabr.email_address_id and eabr.deleted = 0 ' . ' group by p.id ' . ' LIMIT ' . $this->start . ',200'; $resource = mysqli_query($sugarTableConnection, $selectSugarParentsTableSql); if ($resource->num_rows > 0) { $this->start = $this->start + $resource->num_rows; while ($row = $resource->fetch_assoc()) { $newParent['created'] = strtotime($row['date_entered']); $newParent['createdby_sugar_id'] = $row['created_by']; $newParent['status'] = !$row['deleted']; $newParent['f_name'] = $row['first_name']; $newParent['l_name'] = $row['last_name']; $newParent['phone_home'] = $row['phone_home']; $newParent['phone_work'] = $row['phone_work']; $newParent['phone_mobile'] = $row['phone_mobile']; $newParent['address_street1'] = $row['primary_address_street']; $newParent['address_street2'] = ''; $newParent['address_city'] = $row['primary_address_city']; $newParent['address_state'] = $row['primary_address_state']; $newParent['address_postalcode'] = $row['primary_address_postalcode']; $newParent['address_country'] = $row['primary_address_country']; $newParent['whmcs_id'] = $row['whmcs_id']; $newParent['sms'] = (int) $row['receive_sms']; $newParent['sugar_id'] = $row['id']; if (isset($row['email_address']) && $row['email_address'] != '' && trim($row['first_name'] . ' ' . $row['last_name']) != '' && !JUserHelper::getUserId($row['email_address'])) { $newParent['juser_id'] = $this->addJoomlaUser(strtolower($row['email_address']), $row['first_name'] . ' ' . $row['last_name'], strtolower($row['email_address']), JUserHelper::genRandomPassword()); } else { $newParent['juser_id'] = 0; } $parentTable = new Sp4kTablesBase('#__sp4k_parent_items'); $parentTable->save($newParent); } } else { $this->continue = false; } }
private function doLoginUser($user, $options = array()) { $app = JFactory::getApplication(); if ($app->isAdmin()) { return true; } $session = JFactory::getSession(); $old_sessionid = $session->get('old_sessionid', '', 'j2store'); jimport('joomla.user.helper'); $user['id'] = intval(JUserHelper::getUserId($user['username'])); require_once JPATH_ADMINISTRATOR . '/components/com_j2store/helpers/j2store.php'; //cart $helper = J2Store::cart(); if (!empty($old_sessionid)) { $helper->resetCart($old_sessionid, $user['id']); //TODO do the same for wish lists } else { $helper->updateSession($user['id'], $session->getId()); } return true; }
/** * Add message */ public function add() { $user = JXFactory::getUser(); // Store stream $comment = JTable::getInstance('Comment', 'StreamTable'); $message = JTable::getInstance('Stream', 'StreamTable'); $message->load(JRequest::getVar('stream_id')); $user_id = JRequest::getVar('anon', false) ? JUserHelper::getUserId('anon') : $user->id; // People need to be able to read the message to add comment if (!$user->authorise('stream.message.read', $message)) { // No reason this code would ever get here! exit; } $comment->bind(JRequest::get('POST', JREQUEST_ALLOWRAW)); $comment->raw = json_encode(JRequest::get('POST', JREQUEST_ALLOWRAW)); $comment->user_id = $user_id; $comment->group_id = $message->group_id; $comment->store(); // Update group stats, if it is a group message if (!empty($comment->group_id)) { $group = JTable::getInstance('Group', 'StreamTable'); $group->load($comment->group_id); $group->setParam('last_comment', $comment->id); $group->store(); } // Trigger Notification StreamNotification::trigger('profile_post_comment', $comment); // If the updated date is set further than the current date, it is a pinned stream item and shouldn't be updated $now = new JDate(); $updated = new JDate($message->updated); $preventUpdate = $updated->toUnix() > $now->toUnix(); // Check pinned item status too? For now... naa // Update stream stats. Recalculate the count $this->_recalculateCommentCount($comment->stream_id, $preventUpdate); // Get the HTML code to append $tmpl = new StreamTemplate(); header('Content-Type: text/html; charset=UTF-8'); echo $tmpl->set('comment', $comment)->fetch('comment.item'); exit; }
public function update() { if (!isset($this->item->account_id)) { $account = Sp4kAppsAccountApp::getInstance(new Registry(['created' => time()]))->getItem()->update(); $this->item->account_id = $account->id; } if ($this->item->juser_id == null || $this->item->juser_id == 0) { if (isset($this->item->email) && $this->item->email != '' && trim($this->item->f_name . ' ' . $this->item->l_name) != '' && !JUserHelper::getUserId($this->item->email)) { $this->item->juser_id = $this->addJoomlaUser(strtolower($this->item->email), $this->item->f_name . ' ' . $this->item->l_name, strtolower($this->item->email), JUserHelper::genRandomPassword()); } else { $this->item->juser_id = 0; } } if ($this->state->get('children', false)) { foreach ($this->state->get('children') as $child) { $childAppItem = Sp4kAppsChildApp::getInstance(new Registry($child))->getItem(); $childAppItem->account_id = $account->id; $childAppItem->update(); } } $this->item->update(); }
function &getUserObject($user, $options = array()) { JLoader::import('joomla.user.helper'); $instance = new JUser(); if ($id = intval(JUserHelper::getUserId($user['username']))) { $instance->load($id); return $instance; } JLoader::import('joomla.application.component.helper'); $config = JComponentHelper::getParams('com_users'); $defaultUserGroup = $config->get('new_usertype', 2); $acl = JFactory::getACL(); $instance->set('id', 0); $instance->set('name', $user['fullname']); $instance->set('username', $user['username']); $instance->set('password_clear', $user['password_clear']); $instance->set('email', $user['email']); // Result should contain an email (check) $instance->set('usertype', 'deprecated'); $instance->set('groups', array($defaultUserGroup)); return $instance; }
/** * When the user logs in, their session cart should override their db-stored cart. * Current actions take precedence * * @param $user * @param $options * @return unknown_type */ private function doLoginUser($user, $options = array()) { $session = JFactory::getSession(); $old_sessionid = $session->get('old_sessionid'); $user['id'] = intval(JUserHelper::getUserId($user['username'])); // Should check that Tienda is installed first before executing if (!$this->_isInstalled()) { return; } Tienda::load('TiendaHelperCarts', 'helpers.carts'); $helper = new TiendaHelperCarts(); if (!empty($old_sessionid)) { $helper->mergeSessionCartWithUserCart($old_sessionid, $user['id']); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $wishlist_model = JModel::getInstance('WishlistItems', 'TiendaModel'); $wishlist_model->setUserForSessionItems($old_sessionid, $user['id']); } else { $helper->updateUserCartItemsSessionId($user['id'], $session->getId()); } $this->checkUserGroup(); return true; }
/** * Test various ACL action permissions for com_attachments for various users * * @dataProvider provider * * @param string $username The name of ther user (for error outputs) * @param int $admin correct 'core.admin' permission (0/1 interpreted as bool) * @param int $manage correct 'core.manage' permission (0/1 interpreted as bool) * @param int $create correct 'core.create' permission (0/1 interpreted as bool) * @param int $delete correct 'core.delete' permission (0/1 interpreted as bool) * @param int $edit_state correct 'core.edit.state' permission (0/1 interpreted as bool) * @param int $edit correct 'core.edit' permission (0/1 interpreted as bool) * @param int $edit_own correct 'core.edit.own' permission (0/1 interpreted as bool) * @param int $delete_own correct 'attachments.delete.own' permission (0/1 interpreted as bool) */ public function testActions($username, $admin, $manage, $create, $delete, $edit_state, $edit, $edit_own, $delete_own) { $user_id = JUserHelper::getUserId($username); $errmsg = "ERROR: ========> USERNAME={$username} does not exist!"; $this->assertNotEquals((int) $user_id, 0, $errmsg); $canDo = AttachmentsPermissions::getActions((int) $user_id); $errmsg = "----> Failed test for {$username} core.admin for com_attachments, " . " expected {$admin}, got " . $canDo->get('core.admin') . " for " . $username; $this->assertEquals($canDo->get('core.admin'), (bool) $admin, $errmsg); $errmsg = "----> Failed test for {$username} core.manage for com_attachments, " . " expected {$manage}, got " . $canDo->get('core.manage') . " for " . $username; $this->assertEquals($canDo->get('core.manage'), (bool) $manage, $errmsg); $errmsg = "----> Failed test for {$username} core.create for com_attachments, " . " expected {$create}, got " . $canDo->get('core.create') . " for " . $username; $this->assertEquals($canDo->get('core.create'), (bool) $create, $errmsg); $errmsg = "----> Failed test for {$username} core.delete for com_attachments, " . " expected {$delete}, got " . $canDo->get('core.delete') . " for " . $username; $this->assertEquals($canDo->get('core.delete'), (bool) $delete, $errmsg); $errmsg = "----> Failed test for {$username} core.edit.state for com_attachments, " . " expected {$edit_state}, got " . $canDo->get('core.edit.state') . " for " . $username; $this->assertEquals($canDo->get('core.edit.state'), (bool) $edit_state, $errmsg); $errmsg = "----> Failed test for {$username} core.edit for com_attachments, " . " expected {$edit}, got " . $canDo->get('core.edit') . " for " . $username; $this->assertEquals($canDo->get('core.edit'), (bool) $edit, $errmsg); $errmsg = "----> Failed test for {$username} core.edit.own for com_attachments, " . " expected {$edit_own}, got " . $canDo->get('core.edit.own') . " for " . $username; $this->assertEquals($canDo->get('core.edit.own'), (bool) $edit_own, $errmsg); $errmsg = "----> Failed test for {$username} attachments.delete.own for com_attachments, " . " expected {$delete_own}, got " . $canDo->get('attachments.delete.own') . " for " . $username; $this->assertEquals($canDo->get('attachments.delete.own'), (bool) $delete_own, $errmsg); }