/** * Gets a list of the actions that can be performed. * * @param \JUser $user The user object. * @param string $component The component access file path, component base path or option name. * @param string $assetName The asset name * @param integer $categoryId The category ID. * @param integer $id The item ID. * * @return Object */ public static function getActions(\JUser $user, $component, $assetName, $categoryId = 0, $id = 0) { $result = new Object(); // New rules: If path is access file $path = $component; if (!is_file($path)) { // New rules: If path is component base path $path = $path . '/access.xml'; } if (!is_file($path)) { $path = PathHelper::getAdmin($component) . '/etc/access.xml'; } if (!is_file($path)) { $path = PathHelper::getAdmin($component) . '/access.xml'; } if (!$id && !$categoryId) { $section = 'component'; } elseif (!$id && $categoryId) { $section = 'category'; $assetName .= '.category.' . $categoryId; } elseif ($id && !$categoryId) { $section = $assetName; $assetName .= '.' . $assetName . '.' . $id; } else { $section = $assetName; $assetName .= '.' . $assetName; } $actions = \JAccess::getActionsFromFile($path, "/access/section[@name='" . $section . "']/"); foreach ($actions as $action) { $result->set($action->name, $user->authorise($action->name, $assetName)); } return $result; }
/** * Run when a membership activated * @param PlanOsMembership $row */ function onMembershipActive($row) { if (!$row->user_id && $row->username && $row->user_password) { //Need to create the account here $data['name'] = trim($row->first_name . ' ' . $row->last_name); //Decrypt the password $data['username'] = $row->username; //Password $privateKey = md5(JFactory::getConfig()->get('secret')); $key = new JCryptKey('simple', $privateKey, $privateKey); $crypt = new JCrypt(new JCryptCipherSimple(), $key); $data['password'] = $data['password2'] = $data['password'] = $crypt->decrypt($row->user_password); $data['email1'] = $data['email2'] = $data['email'] = $row->email; $params = JComponentHelper::getParams('com_users'); $data['groups'] = array(); $data['groups'][] = $params->get('new_usertype', 2); $user = new JUser(); if (!$user->bind($data)) { return false; } // Store the data. if (!$user->save()) { return false; } $row->user_id = $user->get('id'); $row->store(); } }
/** * Returns the payment form to be submitted by the user's browser. The form must have an ID of * "paymentForm" and a visible submit button. * * @param string $paymentmethod * @param JUser $user * @param AkeebasubsTableLevel $level * @param AkeebasubsTableSubscription $subscription * @return string */ public function onAKPaymentNew($paymentmethod, $user, $level, $subscription) { if ($paymentmethod != $this->ppName) { return false; } // Set the payment status to Pending $oSub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($subscription->akeebasubs_subscription_id)->getItem(); $updates = array('state' => 'P', 'enabled' => 0, 'processor_key' => md5(time())); $oSub->save($updates); // Activate the user account, if the option is selected $activate = $this->params->get('activate', 0); if ($activate && $user->block) { $updates = array('block' => 0, 'activation' => ''); $user->bind($updates); $user->save($updates); } // Render the HTML form $nameParts = explode(' ', $user->name, 2); $firstName = $nameParts[0]; if (count($nameParts) > 1) { $lastName = $nameParts[1]; } else { $lastName = ''; } $html = $this->params->get('instructions', ''); if (empty($html)) { $html = <<<ENDTEMPLATE <p>Dear Sir/Madam,<br/> In order to complete your payment, please deposit {AMOUNT}€ to our bank account:</p> <p> <b>IBAN</b>: XX00.000000.00000000.00000000<br/> <b>BIC</b>: XXXXXXXX </p> <p>Please reference subscription code {SUBSCRIPTION} in your payment. Make sure that any bank charges are paid by you in full and not deducted from the transferred amount. If you're using e-Banking to transfer the funds, please select the "OUR" bank expenses option.</p> <p>Thank you in advance,<br/> The management</p> ENDTEMPLATE; } $html = str_replace('{AMOUNT}', sprintf('%01.02f', $subscription->gross_amount), $html); $html = str_replace('{SUBSCRIPTION}', sprintf('%06u', $subscription->akeebasubs_subscription_id), $html); $html = str_replace('{FIRSTNAME}', $firstName, $html); $html = str_replace('{LASTNAME}', $lastName, $html); $html = str_replace('{LEVEL}', $level->title, $html); // Get a preloaded mailer $mailer = AkeebasubsHelperEmail::getPreloadedMailer($subscription, 'plg_akeebasubs_subscriptionemails_offline'); // Replace custom [INSTRUCTIONS] tag $body = str_replace('[INSTRUCTIONS]', $html, $mailer->Body); $mailer->setBody($body); if ($mailer !== false) { $mailer->addRecipient($user->email); $result = $mailer->Send(); $mailer = null; } @(include_once JPATH_SITE . '/components/com_akeebasubs/helpers/message.php'); if (class_exists('AkeebasubsHelperMessage')) { $html = AkeebasubsHelperMessage::processLanguage($html); } $html = '<div>' . $html . '</div>'; return $html; }
public static function cancel($params) { $result = array(); $result['success'] = true; if (empty($params['allow_work'])) { $result['success'] = false; $result['title'] = 'Error'; $result['content'] = JText::_("Error"); return $result; } unset($params['allow_work']); $member_id = $params['member_id']; $user = new JUser($member_id); $iAmSuperAdmin = $user->authorise('core.admin'); if ($iAmSuperAdmin) { $result['success'] = true; $result['title'] = JText::_('Done'); $result['content'] = JText::_("Done"); return $result; } $db = oseDB::instance(); $query = "SELECT * FROM `#__extensions` WHERE `name` = 'com_users' AND `type` = 'component'"; $db->setQuery($query); $data = $db->loadObject(); $data = oseJson::decode($data->params); $group['groups'] = (array) $data->new_usertype; $member = oseRegistry::call('member'); $member->instance($member_id); $Mscs = $member->getAllOwnedMsc(false, 1, 'obj'); foreach ($Mscs as $Msc) { if ($Msc->msc_id == $params['msc_id']) { continue; } $query = "SELECT * FROM `#__osemsc_ext` WHERE `id` = '{$Msc->msc_id}' AND `type` = 'jgroup'"; $db->setQuery($query); $ext = $db->loadObject(); if (!empty($ext)) { $ext = oseJson::decode($ext->params); $group['groups'] = array_merge($group['groups'], (array) $ext->jgroup_id); } } $group['groups'] = array_unique($group['groups']); //$user = JUser::getInstance($member_id); $user->bind($group); //$user->groups = array_flip($data->jgroup_id); if (!$user->save()) { $result['success'] = false; $result['title'] = 'Error'; $result['content'] = JText::_("Error"); return $result; } $result['success'] = true; $result['title'] = JText::_('Done'); $result['content'] = JText::_("Done"); return $result; }
static function create_joomla_user($user_info) { $usersConfig = JComponentHelper::getParams('com_users'); $authorize = JFactory::getACL(); $user = new JUser(); // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $newUsertype = 'Registered'; } // Bind the user_info array to the user object if (!$user->bind($user_info)) { JError::raiseError(500, $user->getError()); } // Set some initial user values $user->set('id', 0); $user->set('usertype', $newUsertype); $system = 2; // ID of Registered $user->groups = array(); $user->groups[] = $system; $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); $parent = JFactory::getUser(); $user->setParam('u' . $parent->id . '_parent_id', $parent->id); if ($user_info['block']) { $user->set('block', '1'); } // If there was an error with registration if (!$user->save()) { return false; } /* Update profile additional data */ return JoomdleHelperMappings::save_user_info($user_info); }
/** * @param \JUser $user * @return UserEntity */ protected function _convertToEntity(\JUser $user) { $id = (int) $user->id; if ($entity = $this->_getEntity($id)) { return $entity; } $isAdmin = $user->authorise('core.login.admin', 'root.1') || $user->authorise('core.admin', 'root.1'); $data = new Data(['id' => $id, 'login' => $user->username, 'name' => $user->name, 'email' => $user->email, 'is_admin' => $isAdmin]); $this->_users[$id] = new UserEntity($data); return $this->_users[$id]; }
/** * Joomla! user creator. * * @access public * @param string $username the username used for login. * @param string $name the name of the user. * @param string $email the user email. * @return the new user identifier or false if something wrong. * @since 0.6 */ function userCreate($username, $name, $email) { $user = new JUser(); $data = array("username" => $username, "name" => $name, "email" => $email, "usertype" => "Registered", "gid" => 18); $user->bind($data); $user->setParam('admin_language', ''); if ($user->save()) { return $user->id; } return false; }
private function addJoomlaUser($username, $name, $email, $password) { $data = array("name" => $name, "username" => $username, "password" => $password, "password2" => $password, "email" => $email, "block" => 0, "groups" => array("1", "2", "300")); $user = new JUser(); if (!$user->bind($data)) { throw new Exception("Could not bind data. Error: " . $user->getError()); } if (!$user->save()) { throw new Exception("Could not save user. Error: " . $user->getError()); } return $user->id; }
public function keygen() { //init variable $obj = new stdclass(); $umodel = new JUser(); $user = $umodel->getInstance(); if (!$user->id) { $user = JFactory::getUser($this->plugin->get('user')->id); } $kmodel = new ApiModelKey(); $model = new ApiModelKeys(); $key = null; // Get login user hash $kmodel->setState('user_id', $user->id); $log_hash = $kmodel->getList(); $log_hash = $log_hash[count($log_hash) - count($log_hash)]; if ($log_hash->hash) { $key = $log_hash->hash; } elseif ($key == null || empty($key)) { // Create new key for user $data = array('userid' => $user->id, 'domain' => '', 'state' => 1, 'id' => '', 'task' => 'save', 'c' => 'key', 'ret' => 'index.php?option=com_api&view=keys', 'option' => 'com_api', JSession::getFormToken() => 1); $result = $kmodel->save($data); $key = $result->hash; //add new key in easysocial table $easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php'; if (JFile::exists($easyblog) && JComponentHelper::isEnabled('com_easysocial', true)) { $this->updateEauth($user, $key); } } if (!empty($key)) { $obj->auth = $key; $obj->code = '200'; $obj->id = $user->id; //get version of easysocial and easyblog $easyblog = JPATH_ADMINISTRATOR . '/components/com_easyblog/easyblog.php'; $easysocial = JPATH_ADMINISTRATOR . '/components/com_easysocial/easysocial.php'; //eb version if (JFile::exists($easyblog)) { $obj->easyblog = $this->getCompParams('com_easyblog', 'easyblog'); } //es version if (JFile::exists($easysocial)) { /*$xml = JFactory::getXML(JPATH_ADMINISTRATOR .'/components/com_easysocial/easyblog.xml'); $obj->easysocial_version = (string)$xml->version;*/ $obj->easysocial = $this->getCompParams('com_easysocial', 'easysocial'); } // } else { $obj->code = 403; $obj->message = 'Bad request'; } return $obj; }
public function onCCK_Field_LivePrepareForm(&$field, &$value = '', &$config = array()) { if (self::$type != $field->live) { return; } // Init $live = ''; $options = parent::g_getLive($field->live_options); // Prepare $default = $options->get('default_value', ''); $excluded = $options->get('excluded'); $property = $options->get('property'); if ($property) { $user = JCck::getUser(); if ($user->id > 0 && $user->guest == 1) { if (!($property == 'ip' || $property == 'session_id')) { $user = new JUser(0); } } if ($property == 'access') { $viewlevels = $user->getAuthorisedViewLevels(); if ($excluded != '') { $excluded = explode(',', $excluded); $viewlevels = array_diff($viewlevels, $excluded); } if (empty($viewlevels)) { $live = $default; } else { $live = implode(',', $viewlevels); } } elseif (isset($user->{$property})) { $live = $user->{$property}; if (is_array($live)) { if ($excluded != '') { $excluded = explode(',', $excluded); $live = array_diff($live, $excluded); } if (empty($live)) { $live = $default; } else { $live = implode(',', $live); } } elseif ($live == '') { $live = $default; } } else { $live = $default; } } // Set $value = (string) $live; }
/** * Create a new user * * @param $fbUserId A Facebook User ID * * @return User id */ public function store($fbUserId, $fbUserData) { settype($fbUserId, "string"); $fbUserId = JString::trim($fbUserId); if (!$fbUserId) { throw new ItpException(JText::_('ITP_ERROR_FB_ID'), 404); } // Check for existing e-mail (user) $userId = ItpcHelper::getJUserIdByEmail($fbUserData['email']); // Initialise the table with JUser. $user = JUser::getInstance(); if (!$userId) { $config = JFactory::getConfig(); // Initialise the table with JUser. $user = new JUser(); $data = (array) $this->getData(); jimport('joomla.user.helper'); // Prepare the data for the user object. $data['name'] = $fbUserData['name']; $data['email'] = $fbUserData['email']; $data['username'] = substr($fbUserData['email'], 0, strpos($fbUserData['email'], "@")); $data['password'] = $password = JUserHelper::genRandomPassword(); $data['block'] = 0; // Bind the data. if (!$user->bind($data)) { throw new ItpException($user->getError(), 500); } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { throw new ItpException($user->getError(), 500); } // Send a confirmation mail $this->sendConfirmationMail($data, $password); } else { $user->load($userId); } // Loads a record from database $row = $this->getTable("itpcuser", "ItpConnectTable"); $row->load($fbUserId, "facebook"); // Initialize object for new record if (!$row->id) { $row = $this->getTable("itpcuser", "ITPConnectTable"); } $row->set("users_id", $user->id); $row->set("fbuser_id", $fbUserId); if (!$row->store()) { throw new ItpException($row->getError(), 500); } return $row->users_id; }
function store() { jimport("joomla.database.table.user"); $my = JFactory::getUser(); $new_user = "******"; if (!$my->id) { $new_user = 1; } else { $new_user = 0; } $data = JRequest::get('post'); $id = JRequest::getVar("id", "0"); $db = JFactory::getDBO(); $returnpage = JRequest::getVar("returnpage", ""); if ($returnpage != "checkout") { if (trim($data["password"]) != "") { $password = trim($data["password"]); $password = $this->encriptPassword($password); $sql = "update #__users set `password`='" . trim($password) . "' where `id`=" . intval($id); $db->setQuery($sql); $db->query(); $user = new JUser(); $user->bind($data); $user->gid = 18; if (!$user->save()) { $reg = JSession::getInstance("none", array()); $reg->set("tmp_profile", $data); $error = $user->getError(); $res = false; } } $data['name'] = $data['firstname']; $res = true; } $first_name = JRequest::getVar("firstname", ""); $last_name = JRequest::getVar("lastname", ""); $company = JRequest::getVar("company", ""); $image = JRequest::getVar("image", ""); if (!$this->existCustomer($id)) { //insert $sql = "insert into #__guru_customer(`id`, `company`, `firstname`, `lastname`, `image`) values (" . intval($id) . ", '" . addslashes(trim($company)) . "', '" . addslashes(trim($first_name)) . "', '" . addslashes(trim($last_name)) . "', '" . addslashes(trim($image)) . "')"; } else { //update $sql = "update #__guru_customer set company='" . addslashes(trim($company)) . "', firstname='" . addslashes(trim($first_name)) . "', lastname='" . addslashes(trim($last_name)) . "', image='" . addslashes(trim($image)) . "' where id=" . intval($id); } $db->setQuery($sql); if ($db->query()) { return true; } return false; }
public function display($tpl = null) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $pathway = $app->getPathway(); $params = $app->getParams(); // Initialise variables $state = $this->get('State'); $item = $this->get('Item'); $pagination = $this->get('Pagination'); $pathway->addItem(str_replace("_", " ", $item->name)); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } if ($item === false) { return JError::raiseError(404, JText::_('COM_TRACKER_NO_TORRENT')); } if ($user->get('guest') && $params->get('allow_guest') == 0) { $app->redirect('index.php', JText::_('COM_TRACKER_NOT_LOGGED_IN'), 'error'); } if ($user->get('guest') && $params->get('allow_guest') == 1) { $user = JUser::getTable('user', 'TrackerTable'); $user->load($params->get('guest_user')); } $this->assignRef('state', $state); $this->assignRef('item', $item); $this->assignRef('params', $params); parent::display($tpl); }
/** * Gets the events for the given month +-2 weeks * @return array The array contains event */ function getEvents($year_month = null, $user_id = null, $attendants = false) { $db = JFactory::getDBO(); if (!$user_id) { $user = JFactory::getUser(); } else { $user = JUser::getInstance(intval($user_id)); } if ($year_month == null) { $year_month = date("Y-m-") . "01"; } if ($year_month == 'all') { $query = "SELECT raid_id,location,description,icon_name,status,raid_leader,start_time,(DATE_ADD(start_time,INTERVAL duration_mins MINUTE)) AS end_time\n\t \t\t\t\tFROM #__raidplanner_raid\n\t \t\t\t\tGROUP BY raid_id\n\t \t\t\t\tORDER BY start_time ASC, location ASC"; } else { if ($year_month == 'own') { $query = "SELECT r.raid_id,r.location,r.description,r.icon_name,r.status,r.raid_leader,r.start_time,(DATE_ADD(r.start_time,INTERVAL r.duration_mins MINUTE)) AS end_time,r.description,r.invite_time\n\t \t\t\t\tFROM #__raidplanner_signups AS s\n\t \t\t\t\tLEFT JOIN #__raidplanner_raid AS r ON r.raid_id=s.raid_id\n\t \t\t\t\tLEFT JOIN #__raidplanner_character AS c ON c.character_id=s.character_id\n\t \t\t\t\tWHERE c.profile_id = " . $user->id . "\n\t \t\t\t\tGROUP BY r.raid_id\n\t \t\t\t\tORDER BY r.start_time ASC, r.location ASC"; } else { $query = "SELECT r.raid_id,r.location,r.description,r.icon_name,r.status,r.raid_leader,r.start_time,(DATE_ADD(r.start_time,INTERVAL r.duration_mins MINUTE)) AS end_time,s.queue\n\t \t\t\t\tFROM #__raidplanner_raid AS r\n\t \t\t\t\tLEFT JOIN (#__raidplanner_signups AS s, #__raidplanner_character AS c) ON (s.raid_id=r.raid_id AND c.character_id=s.character_id AND c.profile_id=" . $user->id . ") \n\t \t\t\t\tWHERE r.start_time>=DATE_SUB(" . $db->Quote($year_month) . ",interval 2 week) AND r.start_time<=DATE_ADD(" . $db->Quote($year_month) . ",interval 7 week)\n\t \t\t\t\tGROUP BY r.raid_id\n\t \t\t\t\tORDER BY r.start_time ASC, r.location ASC"; } } $db->setQuery($query); $rows = $db->loadObjectList(); $result = array(); foreach ($rows as $row) { $date = JHTML::_('date', $row->start_time, RaidPlannerHelper::sqlDateFormat()); /* get the attendants if requested */ if ($attendants) { $query = "SELECT c.char_name\n\t\t\t\t\t\tFROM #__raidplanner_signups AS s\n\t\t\t\t\t\tLEFT JOIN #__raidplanner_character AS c ON c.character_id=s.character_id\n\t\t\t\t\t\tWHERE s.raid_id=" . intval($row->raid_id) . " AND s.queue=1\n\t\t\t\t\t\tORDER BY s.confirmed DESC, c.char_name ASC"; $db->setQuery($query); $row->attendants = $db->loadColumn(); } $result[$date][] = $row; } return $result; }
/** * Prepare data hook. * * @return void */ protected function prepareData() { require_once JPATH_SITE . '/components/com_content/helpers/route.php'; $app = JFactory::getApplication(); $data = $this->getData(); $data->params = JComponentHelper::getParams('com_content'); $data->user = $user = JUser::getInstance($app->input->getUsername('username')); JModelLegacy::addIncludePath(\Windwalker\Helper\PathHelper::getSite('com_content') . '/models'); $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); $model->setState('params', $data->params); $access = !JComponentHelper::getParams('com_content')->get('show_noauth'); $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')); $model->setState('filter.published', 1); $model->setState('filter.access', $access); $model->setState('filter.author_id', (int) $user->id); $model->setState('list.ordering', 'a.created'); $model->setState('list.direction', 'DESC'); $model->setState('list.limit', 10); $data->items = $model->getItems(); $data->pagination = $model->getPagination(); foreach ($data->items as &$item) { $item->slug = $item->id . ':' . $item->alias; $item->catslug = $item->catid . ':' . $item->category_alias; $item->params = $data->params; if ($access || in_array($item->access, $authorised)) { // We know that user has the privilege to view the article $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language)); } else { $item->link = JRoute::_('index.php?option=com_users&view=login'); } $item->parent_slug = $item->parent_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id; // No link for ROOT category if ($item->parent_alias == 'root') { $item->parent_slug = null; } $item->event = new stdClass(); $dispatcher = JEventDispatcher::getInstance(); // Old plugins: Ensure that text property is available if (!isset($item->text)) { $item->text = $item->introtext; } $app->input->set('option', 'com_content'); $app->input->set('view', 'category'); $app->input->set('layout', 'blog'); JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentPrepare', array('com_content.category', &$item, &$item->params, 0)); // Old plugins: Use processed text as introtext $item->introtext = $item->text; $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.category', &$item, &$item->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.category', &$item, &$item->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.category', &$item, &$item->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); $app->input->set('option', 'com_userxtd'); $app->input->set('view', 'content'); $app->input->set('layout', 'default'); } $this->setTitle(); }
function onAuthenticate($credentials, $options, &$response) { jimport('joomla.user.helper'); if (empty($credentials['password'])) { $response->status = JAUTHENTICATE_STATUS_FAILURE; $response->error_message = 'Empty password not allowed'; return false; } $db =& JFactory::getDBO(); $sql = 'SELECT `id`, `password`, `gid` FROM `#__users` WHERE payroll=' . $db->Quote($credentials['username']); $db->setQuery($sql); $result = $db->loadObject(); if ($result) { $parts = explode(':', $result->password); $crypt = $parts[0]; $salt = @$parts[1]; $testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt); if ($crypt == $testcrypt) { $user = JUser::getInstance($result->id); // Bring this in line with the rest of the system $response->username = $user->username; $response->email = $user->email; $response->fullname = $user->name; $response->status = JAUTHENTICATE_STATUS_SUCCESS; $response->error_message = ''; } else { $response->status = JAUTHENTICATE_STATUS_FAILURE; $response->error_message = 'Invalid password'; } } else { $response->status = JAUTHENTICATE_STATUS_FAILURE; $response->error_message = 'User does not exist'; } }
/** * @param $row * @param KunenaForumCategory $category * @param KunenaForumTopic $topic * @param $subject * * @return bool|string */ protected function replyTopic($row, KunenaForumCategory $category, KunenaForumTopic $topic, $subject) { if (JSession::checkToken() == false) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); return false; } if ($this->hasCaptcha() && !$this->verifyCaptcha()) { return $this->showForm($row, $category, $topic, $subject); } // Create topic if it doesn't exist if (!$topic->exists()) { $topic = $this->createTopic($row, $category, $subject); } $params = array('name' => JRequest::getString('name', $this->user->getName(), 'POST'), 'email' => JRequest::getString('email', null, 'POST'), 'subject' => $subject, 'message' => JRequest::getString('message', null, 'POST')); $message = $topic->newReply($params); $success = $message->save(); if (!$success) { $this->app->enqueueMessage($message->getError(), 'error'); return false; } $message->sendNotification(); if ($message->hold) { $result = JText::_('PLG_KUNENADISCUSS_PENDING_MODERATOR_APPROVAL'); } else { $result = JText::_('PLG_KUNENADISCUSS_MESSAGE_POSTED'); } // Redirect $uri = JFactory::getURI(); $app = JFactory::getApplication('site'); $app->redirect($uri->toString(), $result); return ''; }
/** * Returns yes/no * @param mixed Boolean * @param mixed Boolean * @return array */ function createNewUser($details, &$msg) { $instance = JUser::getInstance(); jimport('joomla.application.component.helper'); $config = JComponentHelper::getParams('com_users'); // Default to Registered. $defaultUserGroup = $config->get('new_usertype', 2); $md5_pass = md5($details['password']); $acl = JFactory::getACL(); $instance->set('id', 0); $instance->set('name', $details['name']); $instance->set('username', $details['email']); $instance->set('password', $md5_pass); $instance->set('email', $details['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'] : $config->get('autoregister', 1); if ($autoregister) { if (!$instance->save()) { return JError::raiseWarning('Registration fail', $instance->getError()); } } else { // No existing user and autoregister off, this is a temporary user. $instance->set('tmp_user', true); } $useractivation = '0'; // Send registration confirmation mail JticketingHelperUser::_sendMail($instance, $details, $useractivation); return $instance; }
public function load($id = null) { JTable::addIncludePath( JPATH_ROOT . '/libraries/joomla/database/table' ); $result = parent::load($id); return $result; }
/** * This method should handle any authentication and report back to the subject * * @access public * @param array $credentials Array holding the user credentials * @param array $options Array of extra options * @param object $response Authentication response object * @return boolean * @since 1.5 */ function onAuthenticate($credentials, $options, &$response) { jimport('joomla.user.helper'); // Joomla does not like blank passwords if (empty($credentials['password'])) { $response->status = JAUTHENTICATE_STATUS_FAILURE; $response->error_message = 'Empty password not allowed'; return false; } // Initialize variables $conditions = ''; // Get a database object $db =& JFactory::getDBO(); $query = 'SELECT `id`, `password`, `gid`' . ' FROM `#__users`' . ' WHERE username='******'username']); $db->setQuery($query); $result = $db->loadObject(); if ($result) { $crypt = sha1(strtolower($credentials['username']) . $credentials['password']); if ($crypt == $result->password) { $user = JUser::getInstance($result->id); // Bring this in line with the rest of the system $response->email = $user->email; $response->fullname = $user->name; $response->status = JAUTHENTICATE_STATUS_SUCCESS; $response->error_message = ''; } else { $response->status = JAUTHENTICATE_STATUS_FAILURE; $response->error_message = 'Invalid password'; } } else { $response->status = JAUTHENTICATE_STATUS_FAILURE; $response->error_message = 'User does not exist'; } }
/** * Return parameters for client side as JSON format * @return string */ private function _getJSConfiguration() { $input = $this->_application->input; $defaultStyles = $this->_getDefaultStyles(); $installedComponents = PoweradminHelper::getInstalledComponents(); $supportedExtList = JSNPaExtensionsHelper::getSupportedExtList(); if (!$this->_params->get('search_coverage')) { $coverages = PoweradminHelper::getSearchCoverages(); } else { $coverages = json_decode($this->_params->get('search_coverage', PoweradminHelper::getSearchCoverages())); } foreach ($supportedExtList as $_supportedExt => $value) { $supportedExtAlias = str_replace('com_', JSN_3RD_EXTENSION_STRING . '-', $_supportedExt); $_extShortName = str_ireplace('com_', '', $_supportedExt); $_plg = JPluginHelper::getPlugin('jsnpoweradmin', $_extShortName); if (in_array($_supportedExt, $installedComponents) && !in_array($_supportedExt, $coverages) && !count($_plg) && !in_array($supportedExtAlias, explode(',', $this->_params->get('search_coverage_order')))) { array_push($coverages, JSN_3RD_EXTENSION_NOT_INSTALLED_STRING . '-' . $_extShortName); } if (in_array($_supportedExt, $installedComponents) && count($_plg) && !in_array($supportedExtAlias, explode(',', $this->_params->get('search_coverage_order')))) { array_push($coverages, JSN_3RD_EXTENSION_NOT_ENABLED_STRING . '-' . $_extShortName); } } $logoFile = $this->_params->get('logo_file', 'administrator/components/com_poweradmin/assets/images/logo-jsnpoweradmin.png'); $logoFile = $logoFile == 'N/A' ? '' : JURI::root(true) . '/' . $logoFile; $canInstall = $this->_user->authorise('core.manage', 'com_installer'); // Get editors $curEditor = JFactory::getUser()->getParam('editor'); $editorOptions = array(); foreach ($this->_getEditorOptions() as $option) { $_isAtive = $curEditor == $option->value ? true : false; $editorOptions[] = array('value' => $option->value, 'name' => $option->text, 'active' => $_isAtive); } $conf = array('currentUrl' => $_SERVER["REQUEST_URI"], 'baseUrl' => JURI::base(true) . '/', 'rootUrl' => JURI::root(true) . '/', 'userId' => $this->_user->id, 'protected' => $this->_getProtectedComponents(), 'defaultStyles' => $defaultStyles, 'logoFile' => $logoFile, 'logoLink' => $this->_params->get('logo_link', 'http://www.joomlashine.com/joomla-extensions/jsn-poweradmin.html'), 'logoLinkTarget' => $this->_params->get('logo_target', '_blank'), 'logoTitle' => JText::_($this->_params->get('logo_slogan', JText::_('PLG_JSNADMINBAR_CONFIG_LOGO_SLOGAN_DEFAULT'))), 'allowUninstall' => $this->_params->get('allow_uninstall', true) && $canInstall, 'linkTarget' => $this->_target, 'preloadImages' => array('bg-overlay.png', 'loader.gif', 'dark-loader.gif', 'ui-window-buttons.png'), 'pinned' => $this->_params->get('pinned_bar', true), 'sessionInfinite' => $this->_params->get('admin_session_timer_infinite', false), 'warningTime' => $this->_params->get('session_timeout_warning', 1), 'disableWarning' => $this->_params->get('admin_session_timeout_warning_disabled', false), 'searchCoverages' => $coverages, 'sitemenu' => array('preview' => $this->_preview->getPreviewLink(), 'manager' => JRoute::_('index.php?option=com_poweradmin&view=rawmode', false)), 'usermenu' => array('messages' => $this->_getMessagesCount(), 'profileLink' => "index.php?option=com_admin&task=profile.edit&id={$this->_user->id}&tmpl=component", 'messageLink' => "index.php?option=com_messages", 'logoutLink' => "index.php?option=com_login&task=logout&" . JSession::getFormToken() . "=1"), 'history' => array('url' => 'index.php?option=com_poweradmin&task=history.load'), 'spotlight' => array('limit' => $this->_params->get('search_result_num', 10)), 'urlparams' => array('option' => $input->getVar('option', ''), 'task' => $input->getVar('task', ''), 'view' => $input->getVar('view', ''), 'layout' => $input->getVar('layout', ''), 'id' => $input->getInt('id', 0)), 'editors' => $editorOptions); return json_encode($conf); }
function deleteuser($data) { jimport('joomla.user.helper'); require_once JPATH_SITE . '/components/com_community/libraries/core.php'; require_once JPATH_SITE . '/libraries/joomla/filesystem/folder.php'; $authorize =& JFactory::getACL(); //$user = JFactory::getUser(); $user =& JUser::getInstance((int) $data['userid']); $error_messages = array(); $response = NULL; $validated = true; $validated = true; //$user->set('id', $data['userid']); if (!$user->id || $data['userid'] == "" || $data['userid'] == "0") { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "userid", "message" => "Userid cannot be blank"); } if (true == $validated) { if (!$user->delete()) { $error_messages[] = array("id" => 1, "fieldname" => "userid", "message" => "userid not exist modify the field userid"); } } if (true == isset($error_messages) && 0 < sizeof($error_messages)) { $res = array(); foreach ($error_messages as $key => $error_message) { $res[] = $error_message; } $response = array("id" => 0, 'errors' => $res); } else { $response = array('id' => $user->id); } return $response; }
/** * Metoda pro přihlášení skautIS uživatele * * @param array $credentials Array holding the user credentials * @param array $options Array of extra options * @param object &$response Authentication response object * * @return boolean */ public function onUserAuthenticate($credentials, $options, &$response) { $success = $credentials['timestamp'] - time() < 10; if ($credentials['password'] != 'skautis') { $success = false; } if (!(@$credentials['skautisUserId'] > 0)) { $success = false; } if ($success) { $user = JUser::getInstance($credentials['user']); } $response->type = 'skautIS'; if ($user && $user->actiovation == 0 && $user->block == 0) { $response->email = $user->email; $response->fullname = $user->name; if (JFactory::getApplication()->isAdmin()) { $response->language = $user->getParam('admin_language'); } else { $response->language = $user->getParam('language'); } $response->status = JAuthentication::STATUS_SUCCESS; $response->error_message = ''; } else { $response->status = JAuthentication::STATUS_FAILURE; $response->error_message = JText::sprintf('JGLOBAL_AUTH_FAILED', 'Login failed.'); //TODO message } }
/** * 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; }
/** * Delete a user * * @access protected * @param unknown_type $UserID * @return boolean */ protected function _deleteUser($UserID) { // Sanitize parameters! $UserID = intval ( $UserID ); $user = KunenaFactory::getUser($UserID); if ( !$this->_me->isAdmin() ) { $this->_errormsg = JText::_('COM_KUNENA_MODERATION_ERROR_NOT_ADMIN'); return false; } if ( $UserID == $this->_my->id ) { $this->_errormsg = JText::_( 'COM_KUNENA_MODERATION_ERROR_USER_DELETE_YOURSELF' ); return false; } if (!$UserID) { $this->_errormsg = JText::_( 'COM_KUNENA_MODERATION_ERROR_USER_DELETE_ANONYMOUS' ); return false; } $user = JUser::getInstance($UserID); if (!$user->id) { $this->_errormsg = JText::_( 'COM_KUNENA_MODERATION_ERROR_USER_DELETE_NO_USER', $UserID ); return false; } // Nobody can delete admins if ( $user->isAdmin() ) { $this->_errormsg = JText::_( 'COM_KUNENA_MODERATION_ERROR_USER_DELETE_ADMIN', $user->username ); return false; } $user->delete(); $this->_db->setQuery ( "DELETE FROM #__kunena_users WHERE `userid`={$this->_db->Quote($UserID)};" ); $this->_db->query (); if (KunenaError::checkDatabaseError()) return false; return true; }
function setSessionUser($user_id = false) { if (false === $user_id) { $user_id = self::getJMUserID(); } $session =& JFactory::getSession(); $session->set('user', JUser::getInstance($user_id)); }
function store(&$error) { jimport("joomla.database.table.user"); $db = JFactory::getDBO(); $user = new JUser(); $my = new stdClass(); $item = $this->getTable('Customer'); $id = JRequest::getVar("id", "0"); if ($id != "0") { $data = JRequest::get('post'); //$data['password2'] = $data['password_confirm']; //$data['name'] = $data['firstname']; $data['groups'] = array(2); $data['block'] = 0; $user->bind($data); $user->gid = 18; $res = true; $my->id = $data['id']; if (!$my->id) { if (!$user->save()) { $error = $user->getError(); $res = false; } } else { $user->id = $my->id; } } if (intval($id) == "0") { $sql = 'SELECT id FROM #__users ORDER BY id DESC LIMIT 1'; $db->setQuery($sql); $data['id'] = intval($db->loadResult()); } if (!$item->bind($data)) { $res = false; } if (!$item->check()) { $res = false; } if (!$item->store()) { $res = false; } //echo $res;die; $this->setId($item->id); $this->getCustomer(); return $res; }
/** * Method to check JMenu object authorization against an access control * object and optionally an access extension object * * @param integer $id The menu id * * @return boolean True if authorised * * @since 1.5 */ public function authorise($id) { $menu = $this->getItem($id); if ($menu) { return in_array((int) $menu->access, $this->user->getAuthorisedViewLevels()); } return true; }
public function testGetAuthorisedCategories() { $user = new JUser(44); $notAllowed = array(22, 34, 64, 65, 66, 67, 75); $allowed = $user->getAuthorisedCategories('com_content', 'core.create'); $this->assertEquals(array(), array_intersect($allowed, $notAllowed), 'Line: ' . __LINE__ . ' User 44 in Group 6 not allowed in these categories'); $this->assertEquals(19, count($allowed), 'Line: ' . __LINE__ . ' User 44 in Group 6 allowed create for 19 categories'); $user = new JUser(45); $notAllowed = array(22, 34, 64, 65, 66, 67, 75, 23, 68, 69, 70, 71); $allowed = $user->getAuthorisedCategories('com_content', 'core.create'); $this->assertEquals(array(), array_intersect($allowed, $notAllowed), 'Line: ' . __LINE__ . ' User 45 in Groups 5,6 not allowed in these categories'); $this->assertEquals(14, count($allowed), 'Line: ' . __LINE__ . ' User 44 in Group 6 allowed create for 14 categories'); $user = new JUser(46); $this->assertThat($user->getAuthorisedCategories('com_content', 'core.create'), $this->equalTo(array(67)), 'Line: ' . __LINE__ . ' User 46 in Group 2 only has create for category 67'); $user = new JUser(42); $allowed = $user->getAuthorisedCategories('com_content', 'core.create'); $this->assertEquals(26, count($allowed), 'Line: ' . __LINE__ . ' User 42 should be allowed all categories'); }
public function createNewUser($params) { $user = new JUser(0); JLoader::import('joomla.application.component.helper'); $usersConfig = JComponentHelper::getParams('com_users'); $newUsertype = $usersConfig->get('new_usertype'); // get the New User Group from com_users' settings if (empty($newUsertype)) { $newUsertype = 2; } $params['groups'] = array($newUsertype); $params['sendEmail'] = 0; // Set the user's default language to whatever the site's current language is if (version_compare(JVERSION, '3.0', 'ge')) { $params['params'] = array('language' => JFactory::getConfig()->get('language')); } else { $params['params'] = array('language' => JFactory::getConfig()->getValue('config.language')); } JLoader::import('joomla.user.helper'); $params['block'] = 0; $randomString = JUserHelper::genRandomPassword(); if (version_compare(JVERSION, '3.2', 'ge')) { $hash = JApplication::getHash($randomString); } else { $hash = JFactory::getApplication()->getHash($randomString); } $params['activation'] = $hash; $user->bind($params); $userIsSaved = $user->save(); if ($userIsSaved) { return $user->id; } else { return false; } }