protected function prepareDisplay($preconfig) { if (JCck::getConfig_Param('debug', 0)) { jimport('joomla.error.profiler'); $profiler = new JProfiler(); } $app = JFactory::getApplication(); $this->form = $this->get('Form'); $this->option = $app->input->get('option', ''); $this->item = $this->get('Item'); $this->state = $this->get('State'); $option = $this->option; $params = new JRegistry(); $view = $this->getName(); $isNew = 1; $live = ''; $lives = array(); $variation = ''; jimport('cck.base.form.form'); include_once JPATH_LIBRARIES_CCK . '/base/form/form_inc.php'; if (isset($config['id'])) { JFactory::getSession()->set('cck_hash_seblod_form', JApplication::getHash($id . '|' . $type->name . '|' . $config['id'])); } $this->config =& $config; $this->data =& $data; $this->id =& $id; $this->isNew =& $isNew; $this->params =& $params; $this->stage =& $stage; $this->type =& $type; $title = isset($type->title) ? $type->title : ''; $name = isset($type->name) ? $type->name : ''; $this->addToolbar($title, $name); }
public function getHash($seed = '') { if (DiscussHelper::getJoomlaVersion() >= '2.5') { return JApplication::getHash($seed); } return JUtility::getHash($seed); }
private function loginSite() { $app = JFactory::getApplication(); $db = JFactory::getDbo(); // already logedin if (JFactory::getUser()->id) { return; } $query = $db->getQuery(true)->select('userid')->from('#__session')->where('session_id = ' . $db->quote($app->input->cookie->get(md5(JApplication::getHash('administrator')))))->where('client_id = 1')->where('guest = 0'); $db->setQuery($query); $userid = $db->loadResult(); // no backend session found; if (!$userid) { return; } $user = JFactory::getUser($userid); // user load failed if ($user instanceof Exception || $user->get('block') == 1) { return; } $session = JFactory::getSession(); $session->set('user', $user); $app->checkSession(); $query = $db->getQuery(true)->update($db->quoteName('#__session'))->set($db->quoteName('guest') . ' = ' . $db->quote($user->get('guest')))->set($db->quoteName('username') . ' = ' . $db->quote($user->get('username')))->set($db->quoteName('userid') . ' = ' . (int) $user->get('id'))->where($db->quoteName('session_id') . ' = ' . $db->quote($session->getId())); $db->setQuery($query); $db->execute(); $app->redirect('index.php'); }
/** * Verifies the validity of a username/e-mail address * combination and creates a token to verify the request * was initiated by the account owner. The token is * sent to the account owner by e-mail * * @since 1.5 * @param string Username string * @param string E-mail address * @return bool True on success/false on failure */ function requestReset($email) { jimport('joomla.mail.helper'); jimport('joomla.user.helper'); $db = JFactory::getDBO(); // Make sure the e-mail address is valid if (!JMailHelper::isEmailAddress($email)) { $this->setError(JText::_('COM_CITRUSCART_EMAIL_ADDRESS_IS_INVALID')); return false; } // Build a query to find the user $query = 'SELECT id FROM #__users' . ' WHERE email = ' . $db->q($email) . ' AND block = 0'; $db->setQuery($query); // Check the results if (!($id = $db->loadResult())) { $this->setError(JText::_('COM_CITRUSCART_COULD_NOT_FIND_USER')); return false; } // Generate a new token $token = JApplication::getHash(JUserHelper::genRandomPassword()); $query = 'UPDATE #__users' . ' SET activation = ' . $db->q($token) . ' WHERE id = ' . (int) $id . ' AND block = 0'; $db->setQuery($query); // Save the token if (!$db->query()) { $this->setError(JText::_('COM_CITRUSCART_DATABASE_ERROR')); return false; } // Send the token to the user via e-mail if (!$this->_sendConfirmationMail($email, $token)) { return false; } return true; }
function onAfterInitialise() { $app = JFactory::getApplication(); // No remember me for admin if ($app->isAdmin()) { return; } $user = JFactory::getUser(); if ($user->get('guest')) { $hash = JApplication::getHash('JLOGIN_REMEMBER'); if ($str = JRequest::getString($hash, '', 'cookie', JREQUEST_ALLOWRAW | JREQUEST_NOTRIM)) { jimport('joomla.utilities.simplecrypt'); $credentials = array(); $goodCookie = true; $filter = JFilterInput::getInstance(); // Create the encryption key, apply extra hardening using the user agent string. // Since we're decoding, no UA validity check is required. $privateKey = JApplication::getHash(@$_SERVER['HTTP_USER_AGENT']); $key = new JCryptKey('simple', $privateKey, $privateKey); $crypt = new JCrypt(new JCryptCipherSimple(), $key); try { $str = $crypt->decrypt($str); if (!is_string($str)) { throw new Exception('Decoded cookie is not a string.'); } $cookieData = json_decode($str); if (null === $cookieData) { throw new Exception('JSON could not be docoded.'); } if (!is_object($cookieData)) { throw new Exception('Decoded JSON is not an object.'); } // json_decoded cookie could be any object structure, so make sure the // credentials are well structured and only have user and password. if (isset($cookieData->username) && is_string($cookieData->username)) { $credentials['username'] = $filter->clean($cookieData->username, 'username'); } else { throw new Exception('Malformed username.'); } if (isset($cookieData->password) && is_string($cookieData->password)) { $credentials['password'] = $filter->clean($cookieData->password, 'string'); } else { throw new Exception('Malformed password.'); } $return = $app->login($credentials, array('silent' => true)); if (!$return) { throw new Exception('Log-in failed.'); } } catch (Exception $e) { $config = JFactory::getConfig(); $cookie_domain = $config->get('cookie_domain', ''); $cookie_path = $config->get('cookie_path', '/'); // Clear the remember me cookie setcookie(JApplication::getHash('JLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain); JLog::add('A remember me cookie was unset for the following reason: ' . $e->getMessage(), JLog::WARNING, 'security'); } } } }
/** * Testing JApplication::getHash * * @return void */ public function testGetHash() { // Temporarily override the config cache in JFactory. $temp = JFactory::$config; JFactory::$config = new JObject(array('secret' => 'foo')); $this->assertThat(JApplication::getHash('This is a test'), $this->equalTo(md5('foo' . 'This is a test')), 'Tests that the secret string is added to the hash.'); JFactory::$config = $temp; }
/** * Auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 */ protected function populateState() { $input = JFactory::getApplication()->input; $basename = $input->cookie->getString(JApplication::getHash($this->_context . '.basename'), '__SITE__'); $this->setState('basename', $basename); $compressed = $input->cookie->getInt(JApplication::getHash($this->_context . '.compressed'), 1); $this->setState('compressed', $compressed); }
public function getUrl() { if (!isset($this->url)) { $application = JFactory::getApplication(); $hash = JApplication::getHash($this->id); $this->url = JRoute::_('index.php?option=com_k2&view=attachments&task=download&id=' . $this->id . '&hash=' . $hash, true, -1); } return $this->url; }
public static function cartEnter() { require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'opctracking.php'; $hash2 = uniqid('opc', true); $hashn = JApplication::getHash('opctracking'); $hash = JRequest::getVar($hashn, $hash2, 'COOKIE'); if ($hash2 == $hash) { OPCtrackingHelper::setCookie($hash); } }
function alreadyVoted($id) { $mainframe = JFactory::getApplication(); if (MijopollsHelper::is30()) { $cookieName = JApplication::getHash($mainframe->getName() . 'poll' . $id); } else { $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $id); } $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT'); return $voted; }
/** * This method should handle any logout logic and report back to the subject * * @param array $user Holds the user data. * @param array $options Array holding options (client, ...). * * @return object True on success * @since 1.5 */ public function onUserLogout($user, $options = array()) { if (JFactory::getApplication()->isSite()) { // Create the cookie $hash = JApplication::getHash('plgSystemLogout'); $conf = JFactory::getConfig(); $cookie_domain = $conf->get('config.cookie_domain', ''); $cookie_path = $conf->get('config.cookie_path', '/'); setcookie($hash, true, time() + 86400, $cookie_path, $cookie_domain); } return true; }
static function getName() { $clientId = JRequest::getInt('client', 0, 'get'); $client = $clientId ? 'administrator' : 'site'; $hash = ''; if (method_exists('JUtility', 'getHash')) { $hash = JUtility::getHash($client); } else { $hash = JApplication::getHash($client); } return $hash; }
function logout($method, $params) { $username = $params[0]; $mainframe = JFactory::getApplication('site'); $id = JUserHelper::getUserId($username); $error = $mainframe->logout($id, array ( 'clientid' => 0, 'skip_joomdlehooks' => 1)); $r = JApplication::getHash('JLOGIN_REMEMBER'); return $r; }
/** * Gets the current language * * @param boolean $detectBrowser Flag indicating whether to use the browser language as a fallback. * * @return string The language string * * @since 3.1 */ public static function getCurrentLanguage($detectBrowser = true) { $app = JFactory::getApplication(); $langCode = $app->input->cookie->getString(JApplication::getHash('language')); // No cookie - let's try to detect browser language or use site default if (!$langCode) { if ($detectBrowser) { $langCode = JLanguageHelper::detectLanguage(); } else { $langCode = JComponentHelper::getParams('com_languages')->get('site', 'en-GB'); } } return $langCode; }
public function activate($token) { $config = JFactory::getConfig(); $userParams = $this->getUserParams(); JPluginHelper::importPlugin('user'); $userId = $this->getUserId($token); if (!$userId) { $this->setError(JText::_('COM_USERS_ACTIVATION_TOKEN_NOT_FOUND')); return false; } $user = JFactory::getUser($userId); $usermail = JSFactory::getModel('usermailactivation', 'jshop'); $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::base(); // Admin activation is on and user is verifying their email if ($userParams->get('useractivation') == 2 && !$user->getParam('activate', 0)) { $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], false); $user->set('activation', $data['activation']); $user->setParam('activate', 1); $usermail->setData($data); if (!$usermail->sendToAdmin()) { $this->setError($usermail->getError()); return false; } } elseif ($userParams->get('useractivation') == 2 && $user->getParam('activate', 0)) { $user->set('activation', ''); $user->set('block', '0'); $user->setParam('activate', 0); $usermail->setData($data); if (!$usermail->send()) { $this->setError($usermail->getError()); return false; } } else { $user->set('activation', ''); $user->set('block', '0'); } if (!$user->save()) { $this->setError(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED', $user->getError())); $user = false; } JDispatcher::getInstance()->trigger('onAfterUserActivate', array(&$this, &$token, &$user)); return $user; }
function onAfterInitialise() { $app = JFactory::getApplication(); // No remember me for admin if ($app->isAdmin()) { return; } $user = JFactory::getUser(); if ($user->get('guest')) { $hash = JApplication::getHash('JLOGIN_REMEMBER'); if ($str = JRequest::getString($hash, '', 'cookie', JREQUEST_ALLOWRAW | JREQUEST_NOTRIM)) { jimport('joomla.utilities.simplecrypt'); // Create the encryption key, apply extra hardening using the user agent string. // Since we're decoding, no UA validity check is required. $privateKey = JApplication::getHash(@$_SERVER['HTTP_USER_AGENT']); $key = new JCryptKey('simple', $privateKey, $privateKey); $crypt = new JCrypt(new JCryptCipherSimple(), $key); $str = $crypt->decrypt($str); $cookieData = @unserialize($str); // Deserialized cookie could be any object structure, so make sure the // credentials are well structured and only have user and password. $credentials = array(); $filter = JFilterInput::getInstance(); $goodCookie = true; if (is_array($credentials)) { if (isset($cookieData['username']) && is_string($cookieData['username'])) { $credentials['username'] = $filter->clean($cookieData['username'], 'username'); } else { $goodCookie = false; } if (isset($cookieData['password']) && is_string($cookieData['password'])) { $credentials['password'] = $filter->clean($cookieData['password'], 'string'); } else { $goodCookie = false; } } else { $goodCookie = false; } if (!$goodCookie || !$app->login($credentials, array('silent' => true))) { $config = JFactory::getConfig(); $cookie_domain = $config->get('cookie_domain', ''); $cookie_path = $config->get('cookie_path', '/'); // Clear the remember me cookie setcookie(JApplication::getHash('JLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain); } } } }
/** * Auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 3.5.0 */ protected function populateState() { // Joomla 3 if (version_compare(JVERSION, '3.0', 'ge')) { $input = JFactory::getApplication()->input; $basename = $input->cookie->getString(JApplicationHelper::getHash($this->_context . '.basename'), '__SITE__'); $this->setState('basename', $basename); $compressed = $input->cookie->getInt(JApplicationHelper::getHash($this->_context . '.compressed'), 1); $this->setState('compressed', $compressed); } else { $basename = JRequest::getString(JApplication::getHash($this->_context . '.basename'), '__SITE__', 'cookie'); $this->setState('basename', $basename); $compressed = JRequest::getInt(JApplication::getHash($this->_context . '.compressed'), 1, 'cookie'); $this->setState('compressed', $compressed); } }
public static function getToken() { $session = JFactory::getSession(); $user = JFactory::getUser(); $token = $session->get('session.token', null, 'wf'); //create a token if ($token === null) { $token = self::_createToken(12); $session->set('session.token', $token, 'wf'); } if (method_exists('JApplication', 'getHash')) { return 'wf' . JApplication::getHash($user->get('id', 0) . $token); } else { return 'wf' . JUtility::getHash($user->get('id', 0) . $token); } }
function getVoted() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $mainframe = JFactory::getApplication(); $poll_id = JRequest::getInt('id', 0); $option_id = JRequest::getInt('voteid', 0); $poll = JTable::getInstance('Poll', 'Table'); if (!$poll->load($poll_id) || $poll->published != 1) { $mainframe->redirect('index.php', JText::_('ALERTNOTAUTH')); //JError::raiseWarning(404, JText::_('ALERTNOTAUTH')); return; } require_once JPATH_COMPONENT . '/models/poll.php'; $model = new MijopollsModelPoll(); if (MijopollsHelper::is15()) { $params = new JParameter($poll->params); $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id); } else { $params = new JRegistry($poll->params); $cookieName = JApplication::getHash($mainframe->getName() . 'poll' . $poll_id); } $voted_cookie = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT'); $voted_ip = $model->ipVoted($poll, $poll_id); if ($params->get('ip_check') and ($voted_cookie or $voted_ip or !$option_id)) { if ($voted_cookie || $voted_ip) { $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); $tom = "error"; } if (!$option_id) { $msg = JText::_('COM_MIJOPOLLS_NO_SELECTED'); $tom = "error"; } $this->_voted = 0; } else { if ($model->vote($poll_id, $option_id)) { $this->_voted = 1; //Set cookie showing that user has voted setcookie($cookieName, '1', time() + 60 * $poll->lag); } else { $this->_voted = 0; } } return $this->_voted = 1; }
public function doEmailVerificationAndBlocking() { $task = $this->input->getCmd('task'); if ($task == 'activate') { $activationKey = $this->input->get('activation', null, 'raw'); if (is_null($activationKey)) { $activationKey = $this->input->get('token', null, 'raw'); } $user_id = $this->getUserId($activationKey); } else { // Code for temporary user id $mySess = JFactory::getSession(); $tmpUser = $mySess->get('tmpUser', 0, 'default'); $user_id = $tmpUser->id; } //invalid request, joomla will handle it if (!$user_id) { return; } // do we need approval if ($this->isApprovalRequired($user_id) == false) { return; } // --- mark & block the user $user = JUser::getInstance($user_id); $user->setParam(self::PARAM_EMAIL_VERIFIED, '1'); $user->set('block', '1'); jimport('joomla.user.helper'); // Work for both Joomla 3 and Joomla 2.5 series $newActivationKey = JVERSION >= '3.0' ? JApplication::getHash(JUserHelper::genRandomPassword()) : JUtility::getHash(JUserHelper::genRandomPassword()); //$newActivationKey=JUtility::getHash( JUserHelper::genRandomPassword()); // generate new activation // save new activation key by which our admin can enable user $user->set('activation', $newActivationKey); //$this->activation = $newActivationKey; if (!$user->save()) { // JError::raiseWarning('', JText::_( $user->getError())); $this->app->redirect('index.php', JText::_('PLG_XIAA_USER_SAVE_ERROR')); } // send an email to admin with a ativation link and profile of user. $this->sendMessage($user_id, self::MESSAGE_APPROVAL); // show message to user // XITODO : redirect to given menu page $this->app->redirect('index.php', JText::_('PLG_XIAA_USER_EMAIL_VERIFIED_AND_ADMIN_WILL_APPROVE_YOUR_ACCOUNT')); }
/** * Main dispatch method * * @access private * @return boolean */ public function onAfterInitialise() { $app = JFactory::getApplication(); // Avoid operations if plugin is executed in backend if ($app->getClientId()) { return; } // If Joomla 3.4+ and JMAP internal link force always the lang url param using the cookie workaround if ($app->input->get('option') == 'com_jmap' && version_compare(JVERSION, '3.4', '>=')) { $lang = $app->input->get('lang'); $sefs = JLanguageHelper::getLanguages('sef'); $lang_codes = JLanguageHelper::getLanguages('lang_code'); if (isset($sefs[$lang])) { $lang_code = $sefs[$lang]->lang_code; // Create a cookie. $conf = JFactory::getConfig(); $cookie_domain = $conf->get('config.cookie_domain', ''); $cookie_path = $conf->get('config.cookie_path', '/'); setcookie(JApplication::getHash('language'), $lang_code, 86400, $cookie_path, $cookie_domain); $app->input->cookie->set(JApplication::getHash('language'), $lang_code); // Set the request var. $app->input->set('language', $lang_code); // Check if remove default prefix is active and the default language is not the current one $defaultSiteLanguage = JComponentHelper::getParams('com_languages')->get('site', 'en-GB'); $pluginLangFilter = JPluginHelper::getPlugin('system', 'languagefilter'); $removeDefaultPrefix = @json_decode($pluginLangFilter->params)->remove_default_prefix; if ($removeDefaultPrefix && $defaultSiteLanguage != $lang_code) { $uri = JUri::getInstance(); $path = $uri->getPath(); // Force the language SEF code in the path $path = $lang . '/' . ltrim($path, '/'); $uri->setPath($path); } } } // Detect if current request come from a bot user agent if ($this->isBotRequest() && $app->input->get('option') == 'com_jmap') { $this->joomlaConfig->set('sef', false); $_SERVER['REQUEST_METHOD'] = 'POST'; // Set dummy nobot var $app->input->post->set('nobotsef', true); $_POST['nobotsef'] = true; } }
private function _getHash() { $mode = $this->params->get('mode'); $user_id = JFactory::getUser()->get('id'); if (!empty($mode)) { $mode .= '.' . $user_id . '.'; } $hash2 = uniqid('cart' . $mode, true); $hash2 = substr($hash2, 0, 50); jimport('joomla.utilities.utility'); if (method_exists('JUtility', 'getHash')) { $hashn = JUtility::getHash('opccart' . $mode); } else { $hashn = JApplication::getHash('opccart' . $mode); } $hashn = substr($hashn, 0, 20); $hash = JRequest::getVar($hashn, $hash2, 'COOKIE'); plgSystemOpccart::_setCookie($hashn, $hash, $this->params->get('cookie_timeout', 2592000)); return $hash; }
/** * Display method for the raw track data. * * @param boolean If true, the view output will be cached * @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JController This object to support chaining. * @since 1.5 * @todo This should be done as a view, not here! */ public function display($cachable = false, $urlparams = false) { // Get the document object. $document = JFactory::getDocument(); $vName = 'tracks'; $vFormat = 'raw'; // Get and render the view. if ($view = $this->getView($vName, $vFormat)) { // Get the model for the view. $model = $this->getModel($vName); // Load the filter state. $app = JFactory::getApplication(); $type = $app->getUserState($this->context . '.filter.type'); $model->setState('filter.type', $type); $begin = $app->getUserState($this->context . '.filter.begin'); $model->setState('filter.begin', $begin); $end = $app->getUserState($this->context . '.filter.end'); $model->setState('filter.end', $end); $categoryId = $app->getUserState($this->context . '.filter.category_id'); $model->setState('filter.category_id', $categoryId); $clientId = $app->getUserState($this->context . '.filter.client_id'); $model->setState('filter.client_id', $clientId); $model->setState('list.limit', 0); $model->setState('list.start', 0); $form = JRequest::getVar('jform'); $model->setState('basename', $form['basename']); $model->setState('compressed', $form['compressed']); $config = JFactory::getConfig(); $cookie_domain = $config->get('cookie_domain', ''); $cookie_path = $config->get('cookie_path', '/'); jimport('joomla.utilities.utility'); setcookie(JApplication::getHash($this->context . '.basename'), $form['basename'], time() + 365 * 86400, $cookie_path, $cookie_domain); setcookie(JApplication::getHash($this->context . '.compressed'), $form['compressed'], time() + 365 * 86400, $cookie_path, $cookie_domain); // Push the model into the view (as default). $view->setModel($model, true); // Push document object into the view. $view->assignRef('document', $document); $view->display(); } }
public function onAfterInitialise() { $app = JFactory::getApplication(); $db = JFactory::getDbo(); $user = JFactory::getUser(); $userId = $app->input->getInt('uid', 0, 'int'); if ($app->isAdmin() || !$app->input->get('su', 0, 'int') || !$userId) { return; } if ($user->id == $userId) { return $app->redirect('index.php', JText::sprintf('You already logged in as user "%s"', $user->name), 'warning'); } if ($user->id) { return $app->redirect('index.php', JText::_('You would login as another user, please logout first'), 'warning'); } $query = $db->getQuery(true)->select('userid')->from('#__session')->where('session_id = ' . $db->quote($app->input->cookie->get(md5(JApplication::getHash('administrator')))))->where('client_id = 1')->where('guest = 0'); $db->setQuery($query); if (!$db->loadResult()) { return $app->redirect('index.php', JText::_('Back-end User Session Expired'), 'error'); } $instance = JFactory::getUser($userId); if ($instance instanceof Exception) { return $app->redirect('index.php', JText::_('User login failed'), 'error'); } if ($instance->get('block') == 1) { return $app->redirect('index.php', JText::_('JERROR_NOLOGIN_BLOCKED'), 'error'); } $instance->set('guest', 0); $session = JFactory::getSession(); $session->set('user', $instance); $app->checkSession(); $query = $db->getQuery(true)->update($db->quoteName('#__session'))->set($db->quoteName('guest') . ' = ' . $db->quote($instance->get('guest')))->set($db->quoteName('username') . ' = ' . $db->quote($instance->get('username')))->set($db->quoteName('userid') . ' = ' . (int) $instance->get('id'))->where($db->quoteName('session_id') . ' = ' . $db->quote($session->getId())); $db->setQuery($query); $db->execute(); $app->redirect('index.php', JText::sprintf('You have login successfully as user "%s"', $instance->name)); }
/** * Method to auto-populate the model state. */ protected function populateState() { // Get the data $data = JRequest::getVar('jform', array(), 'post', 'array'); // Initialise variables $config = JFactory::getConfig(); $cookie_domain = $config->get('config.cookie_domain', ''); $cookie_path = $config->get('config.cookie_path', '/'); // Set the cookies setcookie(JApplication::getHash($this->_context . '.author'), $data['author'], time() + 365 * 86400, $cookie_path, $cookie_domain); setcookie(JApplication::getHash($this->_context . '.copyright'), $data['copyright'], time() + 365 * 86400, $cookie_path, $cookie_domain); setcookie(JApplication::getHash($this->_context . '.email'), $data['email'], time() + 365 * 86400, $cookie_path, $cookie_domain); setcookie(JApplication::getHash($this->_context . '.url'), $data['url'], time() + 365 * 86400, $cookie_path, $cookie_domain); setcookie(JApplication::getHash($this->_context . '.version'), $data['version'], time() + 365 * 86400, $cookie_path, $cookie_domain); setcookie(JApplication::getHash($this->_context . '.license'), $data['license'], time() + 365 * 86400, $cookie_path, $cookie_domain); // Set the state $this->setState('exportpackage.name', $data['name']); $this->setState('exportpackage.author', $data['author']); $this->setState('exportpackage.copyright', $data['copyright']); $this->setState('exportpackage.email', $data['email']); $this->setState('exportpackage.url', $data['url']); $this->setState('exportpackage.version', $data['version']); $this->setState('exportpackage.license', $data['license']); }
function registersave() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $mainframe = JFactory::getApplication(); $jshopConfig = JSFactory::getConfig(); $config = JFactory::getConfig(); $db = JFactory::getDBO(); $params = JComponentHelper::getParams('com_users'); $lang = JFactory::getLanguage(); $lang->load('com_users'); $post = JRequest::get('post'); JPluginHelper::importPlugin('jshoppingcheckout'); $dispatcher = JDispatcher::getInstance(); if ($params->get('allowUserRegistration') == 0) { JError::raiseError(403, JText::_('Access Forbidden')); return; } $usergroup = JTable::getInstance('usergroup', 'jshop'); $default_usergroup = $usergroup->getDefaultUsergroup(); $post['username'] = $post['u_name']; $post['password2'] = $post['password_2']; if ($post['f_name'] == "") { $post['f_name'] = $post['email']; } $post['name'] = $post['f_name'] . ' ' . $post['l_name']; if ($post['birthday']) { $post['birthday'] = getJsDateDB($post['birthday'], $jshopConfig->field_birthday_format); } $dispatcher->trigger('onBeforeRegister', array(&$post, &$default_usergroup)); $row = JTable::getInstance('userShop', 'jshop'); $row->bind($post); $row->usergroup_id = $default_usergroup; $row->password = $post['password']; $row->password2 = $post['password2']; if (!$row->check("register")) { JError::raiseWarning('', $row->getError()); $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl)); return 0; } if ($post["u_name"] == "") { $post["u_name"] = $post['email']; $row->u_name = $post["u_name"]; } if ($post["password"] == "") { $post["password"] = substr(md5('up' . time()), 0, 8); } $user = new JUser(); $data = array(); $data['groups'][] = $params->get('new_usertype', 2); $data['email'] = $post['email']; $data['password'] = $post['password']; $data['password2'] = $post['password2']; $data['name'] = $post['f_name'] . ' ' . $post['l_name']; $data['username'] = $post["u_name"]; $useractivation = $params->get('useractivation'); $sendpassword = $params->get('sendpassword', 1); if ($useractivation == 1 || $useractivation == 2) { jimport('joomla.user.helper'); $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } $user->bind($data); $user->save(); $row->user_id = $user->id; $row->number = $user->id; unset($row->password); unset($row->password2); if (!$db->insertObject($row->getTableName(), $row, $row->getKeyName())) { JError::raiseWarning('', "Error insert in table " . $row->getTableName()); $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl)); return 0; } $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::base(); if ($useractivation == 2) { $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=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['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $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['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username']); } } else { if ($useractivation == 1) { $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=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['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $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']); } } } $dispatcher->trigger('onBeforeRegisterSendMailClient', array(&$post, &$data, &$emailSubject, &$emailBody)); $mailer = JFactory::getMailer(); $mailer->setSender(array($data['mailfrom'], $data['fromname'])); $mailer->addRecipient($data['email']); $mailer->setSubject($emailSubject); $mailer->setBody($emailBody); $mailer->isHTML(false); $return = $mailer->Send(); if ($params->get('useractivation') < 2 && $params->get('mail_to_admin') == 1) { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBodyAdmin = JText::sprintf('COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY', $data['name'], $data['username'], $data['siteurl']); $query = 'SELECT name, email, sendEmail FROM #__users WHERE sendEmail=1'; $db->setQuery($query); $rows = $db->loadObjectList(); foreach ($rows as $rowadm) { $dispatcher->trigger('onBeforeRegisterSendMailAdmin', array(&$post, &$data, &$emailSubject, &$emailBodyAdmin, &$rowadm)); $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $rowadm->email, $emailSubject, $emailBodyAdmin); } } $dispatcher->trigger('onAfterRegister', array(&$user, &$row, &$post, &$useractivation)); if ($useractivation == 2) { $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'); $return = SEFLink("index.php?option=com_jshopping&controller=user&task=login", 1, 1, $jshopConfig->use_ssl); } elseif ($useractivation == 1) { $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'); $return = SEFLink("index.php?option=com_jshopping&controller=user&task=login", 1, 1, $jshopConfig->use_ssl); } else { $message = JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'); $return = SEFLink("index.php?option=com_jshopping&controller=user&task=login", 1, 1, $jshopConfig->use_ssl); } $this->setRedirect($return, $message); }
/** * Method to determine a hash for anti-spoofing variable names * * @param boolean $forceNew If true, force a new token to be created * * @return string Hashed var name * * @since 11.1 */ public static function getFormToken($forceNew = false) { $user = JFactory::getUser(); $session = JFactory::getSession(); $hash = JApplication::getHash($user->get('id', 0) . $session->getToken($forceNew)); return $hash; }
/** * Event onAfterInitialise * * @access public * @param null * @return null */ public function onAfterInitialise() { // If this is the Administrator-application, or if debugging is set, do nothing $application = JFactory::getApplication(); if ($application->isAdmin()) { return; } // Disable browser-detection $application->setDetectBrowser(false); // Detect the language $languageTag = JFactory::getLanguage()->getTag(); $languageInput = JRequest::getString('language'); // Get the bindings $bindings = $this->getBindings(); // Check for the binding of the current language if (!empty($languageInput)) { if (isset($bindings[$languageTag])) { $domain = $bindings[$languageTag]; if (stristr(JURI::current(), $domain) == false) { // Add URL-elements to the domain $domain = $this->getUrlFromDomain($domain); // Replace the current domain with the new domain $currentUrl = JURI::current(); $newUrl = str_replace(JURI::base(), $domain, $currentUrl); // Strip out the sef-language-part $languages = JLanguageHelper::getLanguages('sef'); foreach ($languages as $languageSef => $language) { if ($language->lang_code == $languageTag) { //$newUrl = str_replace('/'.$languageSef.'/', '/', $newUrl); // @todo: This d break; } } // Set the cookie $conf = JFactory::getConfig(); $cookie_domain = $conf->get('config.cookie_domain', ''); $cookie_path = $conf->get('config.cookie_path', '/'); setcookie(JApplication::getHash('language'), $languageTag, time() + 365 * 86400, $cookie_path, $cookie_domain); // Redirect $application->redirect($newUrl); $application->close(); } } } else { // Check if the current default language is correct foreach ($bindings as $languageCode => $domain) { if (stristr(JURI::current(), $domain) == true) { // Set the cookie $conf = JFactory::getConfig(); $cookie_domain = $conf->get('config.cookie_domain', ''); $cookie_path = $conf->get('config.cookie_path', '/'); setcookie(JApplication::getHash('language'), $languageCode, time() + 365 * 86400, $cookie_path, $cookie_domain); // Change the current default language JRequest::setVar('language', $languageCode); JFactory::getLanguage()->setDefault($languageCode); JFactory::getLanguage()->setLanguage($languageCode); break; } } } }
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; } }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { $basename = JRequest::getString(JApplication::getHash($this->_context . '.basename'), '__SITE__', 'cookie'); $this->setState('basename', $basename); $compressed = JRequest::getInt(JApplication::getHash($this->_context . '.compressed'), 1, 'cookie'); $this->setState('compressed', $compressed); }