Exemple #1
1
 public function getHash($seed = '')
 {
     if (DiscussHelper::getJoomlaVersion() >= '2.5') {
         return JApplication::getHash($seed);
     }
     return JUtility::getHash($seed);
 }
Exemple #2
0
 function onAfterInitialise()
 {
     $app = JFactory::getApplication();
     // No remember me for admin
     if ($app->isAdmin()) {
         return;
     }
     $user = JFactory::getUser();
     if ($user->get('guest')) {
         jimport('joomla.utilities.utility');
         $hash = JUtility::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
             $key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);
             $crypt = new JSimpleCrypt($key);
             $str = $crypt->decrypt($str);
             $options = array();
             $options['silent'] = true;
             if (!$app->login(@unserialize($str), $options)) {
                 $config = JFactory::getConfig();
                 $cookie_domain = $config->get('cookie_domain', '');
                 $cookie_path = $config->get('cookie_path', '/');
                 // Clear the remember me cookie
                 setcookie(JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain);
             }
         }
     }
 }
 /**
  * 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::_('INVALID_EMAIL_ADDRESS'));
         return false;
     }
     // Build a query to find the user
     $query = 'SELECT id FROM #__users' . ' WHERE email = ' . $db->Quote($email) . ' AND block = 0';
     $db->setQuery($query);
     // Check the results
     if (!($id = $db->loadResult())) {
         $this->setError(JText::_('COULD_NOT_FIND_USER'));
         return false;
     }
     // Generate a new token
     $token = JUtility::getHash(JUserHelper::genRandomPassword());
     $salt = JUserHelper::getSalt('crypt-md5');
     $hashedToken = md5($token . $salt) . ':' . $salt;
     $query = 'UPDATE #__users' . ' SET activation = ' . $db->Quote($hashedToken) . ' WHERE id = ' . (int) $id . ' AND block = 0';
     $db->setQuery($query);
     // Save the token
     if (!$db->query()) {
         $this->setError(JText::_('DATABASE_ERROR'));
         return false;
     }
     // Send the token to the user via e-mail
     if (!$this->_sendConfirmationMail($email, $token)) {
         return false;
     }
     return true;
 }
Exemple #4
0
 function alreadyVoted($id)
 {
     $mainframe = JFactory::getApplication();
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $id);
     $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     return $voted;
 }
Exemple #5
0
 public function parseLang($vars)
 {
     if (Mijosef::getConfig()->multilang == 0) {
         return;
     }
     if (empty($vars['lang'])) {
         $lang = JRequest::getWord('lang', '');
         if (empty($lang)) {
             return;
         }
         $vars['lang'] = $lang;
     }
     $languages = JLanguageHelper::getLanguages('sef');
     $lang_code = $languages[$vars['lang']]->lang_code;
     // if current language, don't bother
     if ($lang_code == JFactory::getLanguage()->getTag()) {
         //self::checkHomepage($vars['lang']);
         return;
     }
     // Create a cookie
     $conf = JFactory::getConfig();
     $cookie_domain = $conf->get('config.cookie_domain', '');
     $cookie_path = $conf->get('config.cookie_path', '/');
     setcookie(JUtility::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
     // set the request var
     JRequest::setVar('language', $lang_code);
     // set current language
     jimport('joomla.language.language');
     $conf = JFactory::getConfig();
     $debug = $conf->get('debug_lang');
     $lang = JLanguage::getInstance($lang_code, $debug);
     JFactory::$language = $lang;
     self::$_lang = $vars['lang'];
 }
Exemple #6
0
 /**
  * Method to auto-populate the model state.
  *
  * Note. Calling getState in this method will result in recursion.
  *
  * @since	1.6
  */
 protected function populateState()
 {
     jimport('joomla.utilities.utility');
     $basename = JRequest::getString(JUtility::getHash($this->_context . '.basename'), '__SITE__', 'cookie');
     $this->setState('basename', $basename);
     $compressed = JRequest::getInt(JUtility::getHash($this->_context . '.compressed'), 1, 'cookie');
     $this->setState('compressed', $compressed);
 }
Exemple #7
0
 /**
  * Automatically sets the activation token for the user.
  *
  * @return LibUsersDomainEntityUser
  */
 public function requiresActivation()
 {
     jimport('joomla.user.helper');
     $token = JUtility::getHash(JUserHelper::genRandomPassword());
     $salt = JUserHelper::getSalt();
     $hashedToken = sha1($token . $salt) . ':' . $salt;
     $this->activation = $hashedToken;
     return $this;
 }
 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;
 }
Exemple #9
0
 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;
 }
Exemple #10
0
 /**
  * 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 = JUtility::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;
 }
 public 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');
     }
     $hash = 'wf' . JUtility::getHash($user->get('id', 0) . $token);
     return $hash;
 }
Exemple #12
0
 public function getToken()
 {
     $session =& JFactory::getSession();
     $user =& JFactory::getUser();
     //$plugin   = JRequest::getVar('plugin');
     $token = $session->get('session.token', null, 'jce');
     //create a token
     if ($token === null) {
         $token = self::_createToken(12);
         $session->set('session.token', $token, 'jce');
     }
     $hash = 'jce' . JUtility::getHash($user->get('id', 0) . $token);
     return $hash;
 }
Exemple #13
0
 function onAfterInitialise()
 {
     $app = JFactory::getApplication();
     // No remember me for admin
     if ($app->isAdmin()) {
         return;
     }
     $user = JFactory::getUser();
     if ($user->get('guest')) {
         jimport('joomla.utilities.utility');
         $hash = JUtility::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.
             $key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);
             $crypt = new JSimpleCrypt($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(JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain);
             }
         }
     }
 }
Exemple #14
0
 /**
  * Add a vote to an option
  */
 function vote()
 {
     global $mainframe;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // Captcha Controller Patch rev. 4.5.0 Stable
     $dispatcher =& JDispatcher::getInstance();
     $results = $dispatcher->trigger('onCaptchaRequired', array('user.poll'));
     if ($results[0]) {
         $captchaparams = array(JRequest::getVar('captchacode', '', 'post'), JRequest::getVar('captchasuffix', '', 'post'), JRequest::getVar('captchasessionid', '', 'post'));
         $results = $dispatcher->trigger('onCaptchaVerify', $captchaparams);
         if (!$results[0]) {
             JError::raiseWarning('CAPTHCA', JText::_('CAPTCHACODE_DO_NOT_MATCH'));
             $this->display();
             return false;
         }
     }
     $db =& JFactory::getDBO();
     $poll_id = JRequest::getVar('id', 0, '', 'int');
     $option_id = JRequest::getVar('voteid', 0, 'post', 'int');
     $poll =& JTable::getInstance('poll', 'Table');
     if (!$poll->load($poll_id) || $poll->published != 1) {
         JError::raiseWarning(404, JText::_('ALERTNOTAUTH'));
         return;
     }
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id);
     // ToDo - may be adding those information to the session?
     $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             $msg = JText::_('You already voted for this poll today!');
         }
         if (!$option_id) {
             $msg = JText::_('WARNSELECT');
         }
     } else {
         setcookie($cookieName, '1', time() + $poll->lag);
         require_once JPATH_COMPONENT . DS . 'models' . DS . 'poll.php';
         $model = new PollModelPoll();
         $model->vote($poll_id, $option_id);
         $msg = JText::_('Thanks for your vote!');
     }
     // set Itemid id for links
     $menu =& JSite::getMenu();
     $items = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     $this->setRedirect(JRoute::_('index.php?option=com_poll&id=' . $poll_id . ':' . $poll->alias . $itemid, false), $msg);
 }
Exemple #15
0
 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);
     }
 }
Exemple #16
0
 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'));
 }
Exemple #17
0
 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;
 }
Exemple #18
0
 function vote()
 {
     // 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) {
         JError::raiseWarning(404, JText::_('ALERTNOTAUTH'));
         return;
     }
     $model = $this->getModel('Poll');
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id);
     $voted_cookie = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     $voted_ip = $model->ipVoted($poll, $poll_id);
     if ($voted_cookie || $voted_ip || !$option_id) {
         if ($voted_cookie || $voted_ip) {
             $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
             $tom = "error";
         }
         if (!$option_id) {
             $msg = JText::_('COM_ACEPOLLS_NO_SELECTED');
             $tom = "error";
         }
     } else {
         if ($model->vote($poll_id, $option_id)) {
             //Set cookie showing that user has voted
             setcookie($cookieName, '1', time() + 60 * $poll->lag);
         }
         $msg = JText::_('COM_ACEPOLLS_THANK_YOU');
         $tom = "";
         if (JFactory::getUser()->id != 0) {
             JPluginHelper::importPlugin('acepolls');
             $dispatcher =& JDispatcher::getInstance();
             $dispatcher->trigger('onAfterVote', array($poll, $option_id));
         }
     }
     // set Itemid id for links
     $menu =& JSite::getMenu();
     $items = $menu->getItems('link', 'index.php?option=com_acepolls');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     $this->setRedirect(JRoute::_('index.php?option=com_acepolls&view=poll&id=' . $poll_id . ':' . $poll->alias . $itemid, false), $msg, $tom);
 }
Exemple #19
0
 /**
  * before creating the person node, create the user object.
  *
  * @return bool
  */
 protected function _beforeEntityInsert(KCommandContext $context)
 {
     $viewer = get_viewer();
     $firstUser = !(bool) $this->getService('repos://site/users')->getQuery(true)->fetchValue('id');
     jimport('joomla.user.helper');
     $user = clone JFactory::getUser();
     $user->set('id', 0);
     $user->set('name', $this->name);
     $user->set('username', $this->username);
     $user->set('email', $this->email);
     if (!$this->getPassword()) {
         $this->setPassword(JUserHelper::genRandomPassword(32));
     }
     if ($this->getPassword()) {
         $user->set('password', $this->getPassword(true));
         $user->set('password_clear', $this->getPassword());
     }
     $date =& JFactory::getDate();
     $user->set('registerDate', $date->toMySQL());
     $user->set('lastvisitDate', '0000-00-00 00:00:00');
     // if this is the first user being added or
     // (viewer is a super admin and she is adding another super admin)
     if ($firstUser || $viewer->superadmin() && $this->userType == ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR) {
         $user->set('usertype', ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR);
     } elseif ($viewer->admin() && $this->userType == ComPeopleDomainEntityPerson::USERTYPE_ADMINISTRATOR) {
         $user->set('usertype', ComPeopleDomainEntityPerson::USERTYPE_ADMINISTRATOR);
     } else {
         $user->set('usertype', ComPeopleDomainEntityPerson::USERTYPE_REGISTERED);
     }
     //create an activation token
     //@todo we need a global token generator to handle creation and destruction of tokens
     $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword()));
     $user->set('block', '1');
     if (!$user->save()) {
         throw new RuntimeException('Unexpected error when saving user');
         return false;
     }
     $this->userId = $user->id;
     $this->userType = $user->usertype;
     $this->enabled = $user->block ? 0 : 1;
     return true;
 }
Exemple #20
0
 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;
 }
Exemple #21
0
 function onAfterInitialise()
 {
     global $mainframe;
     // No remember me for admin
     if ($mainframe->isAdmin()) {
         return;
     }
     $user =& JFactory::getUser();
     if (!$user->get('gid')) {
         jimport('joomla.utilities.utility');
         $hash = JUtility::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
             $key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);
             $crypt = new JSimpleCrypt($key);
             $str = $crypt->decrypt($str);
             $mainframe->login(unserialize($str));
         }
     }
 }
Exemple #22
0
 /**
  * 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(JUtility::getHash($this->context . '.basename'), $form['basename'], time() + 365 * 86400, $cookie_path, $cookie_domain);
         setcookie(JUtility::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();
     }
 }
Exemple #23
0
 function onAfterInitialise()
 {
     global $mainframe;
     // No remember me for admin
     if ($mainframe->isAdmin()) {
         return;
     }
     $user =& JFactory::getUser();
     if (!$user->get('gid')) {
         jimport('joomla.utilities.utility');
         $hash = JUtility::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.
             $key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);
             $crypt = new JSimpleCrypt($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();
             if (!is_array($credentials)) {
                 return;
             }
             if (!isset($cookieData['username']) || !is_string($cookieData['username'])) {
                 return;
             }
             $credentials['username'] = JFilterInput::clean($cookieData['username'], 'username');
             if (!isset($cookieData['password']) || !is_string($cookieData['password'])) {
                 return;
             }
             $credentials['password'] = JFilterInput::clean($cookieData['password'], 'string');
             if (!$mainframe->login($credentials, array('silent' => true))) {
                 // Clear the remember me cookie
                 setcookie(JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/');
             }
         }
     }
 }
Exemple #24
0
 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::_('deneme'));
         //JError::raiseWarning(404, JText::_('ALERTNOTAUTH'));
         return;
     }
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id);
     $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
             $tom = "error";
         }
         if (!$option_id) {
             $msg = JText::_('COM_ACEPOLLS_NO_SELECTED');
             $tom = "error";
         }
         $this->_voted = 0;
     } else {
         require_once JPATH_COMPONENT . DS . 'models' . DS . 'poll.php';
         $model = new AcepollsModelPoll();
         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;
 }
Exemple #25
0
 /**
  * Add a vote to an option
  */
 function vote()
 {
     global $mainframe;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $db =& JFactory::getDBO();
     $poll_id = JRequest::getVar('id', 0, '', 'int');
     $option_id = JRequest::getVar('voteid', 0, 'post', 'int');
     $poll =& JTable::getInstance('poll', 'Table');
     if (!$poll->load($poll_id) || $poll->published != 1) {
         JError::raiseWarning(404, JText::_('ALERTNOTAUTH'));
         return;
     }
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id);
     // ToDo - may be adding those information to the session?
     $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             $msg = JText::_('You already voted for this poll today!');
         }
         if (!$option_id) {
             $msg = JText::_('WARNSELECT');
         }
     } else {
         setcookie($cookieName, '1', time() + $poll->lag);
         require_once JPATH_COMPONENT . DS . 'models' . DS . 'poll.php';
         $model = new PollModelPoll();
         $model->vote($poll_id, $option_id);
         $msg = JText::_('Thanks for your vote!');
     }
     // set Itemid id for links
     $menu =& JSite::getMenu();
     $items = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     $this->setRedirect(JRoute::_('index.php?option=com_poll&id=' . $poll_id . ':' . $poll->alias . $itemid, false), $msg);
 }
Exemple #26
0
 /**
  * Logout authentication function.
  *
  * Passed the current user information to the onLogoutUser event and reverts the current
  * session record back to 'anonymous' parameters.
  *
  * @param 	int 	$userid   The user to load - Can be an integer or string - If string, it is converted to ID automatically
  * @param	array 	$options  Array( 'clientid' => array of client id's )
  *
  * @access public
  */
 function logout($userid = null, $options = array())
 {
     // Initialize variables
     $retval = false;
     // Get a user object from the JApplication
     $user =& JFactory::getUser($userid);
     // Build the credentials array
     $parameters['username'] = $user->get('username');
     $parameters['id'] = $user->get('id');
     // Set clientid in the options array if it hasn't been set already
     if (empty($options['clientid'])) {
         $options['clientid'][] = $this->getClientId();
     }
     // Import the user plugin group
     JPluginHelper::importPlugin('user');
     // OK, the credentials are built. Lets fire the onLogout event
     $results = $this->triggerEvent('onLogoutUser', array($parameters, $options));
     /*
      * If any of the authentication plugins did not successfully complete
      * the logout routine then the whole method fails.  Any errors raised
      * should be done in the plugin as this provides the ability to provide
      * much more information about why the routine may have failed.
      */
     if (!in_array(false, $results, true)) {
         setcookie(JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/');
         return true;
     }
     // Trigger onLoginFailure Event
     $this->triggerEvent('onLogoutFailure', array($parameters));
     return false;
 }
Exemple #27
0
 /**
  * Person add action creates a new person object.
  * 
  * @param KCommandContext $context Commaind chain context
  * 
  * @return AnDomainEntityAbstract
  */
 protected function _actionAdd(KCommandContext $context)
 {
     //we are not saving this person but just validating it
     $person = parent::_actionAdd($context);
     $data = $context->data;
     $person->userId = PHP_INT_MAX;
     //is assiged automatically
     //manually set the password to make sure there's a password
     $person->setPassword($data->password);
     //add the validations here
     $this->getRepository()->getValidator()->addValidation('username', 'uniqueness')->addValidation('email', 'uniqueness');
     if ($person->validate() === false) {
         throw new AnErrorException($person->getErrors(), KHttpResponse::BAD_REQUEST);
     }
     $person->reset();
     $firsttime = !(bool) $this->getService('repos://site/users')->getQuery(true)->fetchValue('id');
     $user = clone JFactory::getUser();
     $authorize =& JFactory::getACL();
     if ($firsttime) {
         //for now lets make the com_notes assigable to always
         $component = $this->getService('repos://site/components')->find(array('component' => 'com_notes'));
         if ($component) {
             $component->setAssignmentForIdentifier('person', ComComponentsDomainBehaviorAssignable::ACCESS_ALWAYS);
         }
         $datbase = $this->getService('koowa:database.adapter.mysqli');
         //joomla legacy. don't know what happens if it's set to 1
         $query = "INSERT INTO #__users VALUES (62, 'admin', 'admin', '*****@*****.**', '', 'Super Administrator', 0, 1, 25, '', '', '', '')";
         $datbase->execute($query);
         $query = "INSERT INTO #__core_acl_aro VALUES (10,'users','62',0,'Administrator',0)";
         $datbase->execute($query);
         $query = "INSERT INTO #__core_acl_groups_aro_map VALUES (25,'',10)";
         $datbase->execute($query);
         $user =& JFactory::getUser();
         $user = JUser::getInstance(62);
         $this->unregisterCallback('after.add', array($this, 'notifyAdminsNewUser'));
     } else {
         $user->set('id', 0);
         $config =& JComponentHelper::getParams('com_users');
         $user->set('usertype', $config->get('new_usertype'));
         $user->set('gid', $authorize->get_group_id('', $config->get('new_usertype'), 'ARO'));
         if ($this->activationRequired()) {
             jimport('joomla.user.helper');
             $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword()));
             $user->set('block', '1');
         }
     }
     $user->set('name', $person->name);
     $user->set('username', $person->username);
     $user->set('email', $person->email);
     $user->set('password', $person->getPassword(true));
     $date =& JFactory::getDate();
     $user->set('registerDate', $date->toMySQL());
     $user->save();
     $person = $this->getRepository()->find(array('userId' => $user->id));
     //if person is null then user has not been saved
     if (!$person) {
         throw new RuntimeException('Unexpected error when saving user');
     }
     //set the portrait image
     if ($file = KRequest::get('files.portrait', 'raw')) {
         $person->setPortraitImage(array('url' => $file['tmp_name'], 'mimetype' => $file['type']));
     }
     //set the status
     $this->getResponse()->status = KHttpResponse::CREATED;
     $this->setItem($person);
     if (!$person->enabled) {
         $this->registerCallback('after.add', array($this, 'mailActivationLink'));
     } elseif ($this->isDispatched()) {
         if ($context->request->getFormat() == 'html') {
             $context->response->status = 200;
             $this->registerCallback('after.add', array($this, 'login'));
         }
     }
     return $person;
 }
 /**
  * Save user registration and notify users and admins if required
  * @return void
  */
 function register_save()
 {
     global $mainframe;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // Get required system objects
     $user = clone JFactory::getUser();
     $pathway =& $mainframe->getPathway();
     $config =& JFactory::getConfig();
     $authorize =& JFactory::getACL();
     $document =& JFactory::getDocument();
     // If user registration is not allowed, show 403 not authorized.
     $usersConfig =& JComponentHelper::getParams('com_users');
     if ($usersConfig->get('allowUserRegistration') == '0') {
         JError::raiseError(403, JText::_('Access Forbidden'));
         return;
     }
     // Initialize new usertype setting
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 'Registered';
     }
     // Bind the post array to the user object
     if (!$user->bind(JRequest::get('post'), 'usertype')) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     $user->set('usertype', '');
     $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO'));
     $date =& JFactory::getDate();
     $user->set('registerDate', $date->toMySQL());
     // If user activation is turned on, we need to set the activation information
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == '1') {
         jimport('joomla.user.helper');
         $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword()));
         $user->set('block', '1');
     }
     // If there was an error with registration, set the message and display form
     if (!$user->save()) {
         JError::raiseWarning('', JText::_($user->getError()));
         $this->register();
         return false;
     }
     // Send registration confirmation mail
     $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     //Disallow control chars in the email
     UserController::_sendMail($user, $password);
     // Everything went fine, set relevant message depending upon user activation state and display message
     if ($useractivation == 1) {
         $message = JText::_('REG_COMPLETE_ACTIVATE');
     } else {
         $message = JText::_('REG_COMPLETE');
     }
     $this->setRedirect('index.php', $message);
 }
Exemple #29
0
 public function onUserLogin($user, $options = array())
 {
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         $lang_code = $user['language'];
         if (empty($lang_code)) {
             $lang_code = self::_languageFilterData('default_lang');
         }
         self::_languageFilterData('tag', $lang_code);
         // Create a cookie
         $conf = JFactory::getConfig();
         $cookie_domain = $conf->get('config.cookie_domain', '');
         $cookie_path = $conf->get('config.cookie_path', '/');
         setcookie(JUtility::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
     }
 }
Exemple #30
0
    function display($tpl = null)
    {
        $this->mainframe = JFactory::getApplication();
        $db =& JFactory::getDBO();
        $user =& JFactory::getUser();
        $date =& JFactory::getDate();
        $document =& JFactory::getDocument();
        $pathway =& $this->mainframe->getPathway();
        $poll_id = JRequest::getInt('id', 0);
        $poll =& JTable::getInstance('Poll', 'Table');
        $poll->load($poll_id);
        // if id value is passed and poll not published then exit
        if ($poll->id > 0 && $poll->published != 1) {
            JError::raiseError(403, JText::_('Access Forbidden'));
            return;
        }
        // Adds parameter handling
        $temp = new JRegistry();
        $temp->loadJSON($poll->params);
        $params = clone $this->mainframe->getParams();
        $params->merge($temp);
        //Set page title information
        $menu = JSite::getMenu()->getActive();
        // because the application sets a default page title, we need to get it
        // right from the menu item itself
        if (is_object($menu)) {
            $menu_params = new JRegistry();
            $menu_params->loadJSON($menu->params);
            if (!$menu_params->get('page_title')) {
                $params->set('page_title', $poll->title);
            } else {
                $params->set('page_title', $menu_params->get('page_title'));
            }
        } else {
            $params->set('page_title', $poll->title);
        }
        $document->setTitle($params->get('page_title'));
        //Set pathway information
        $pathway->addItem($poll->title, '');
        $params->def('show_page_title', 1);
        $params->def('page_title', $poll->title);
        // Check if there is a poll corresponding to id and if poll is published
        if ($poll->id > 0) {
            if (empty($poll->title)) {
                $poll->id = 0;
                $poll->title = JText::_('COM_ACEPOLLS_SELECT_POLL');
            }
            //get the array of options
            $options =& $this->get('Options');
        } else {
            $options = array();
        }
        // list of polls for dropdown selection
        $pList = $this->get('Polls');
        foreach ($pList as $k => $p) {
            $pList[$k]->url = JRoute::_('index.php?option=com_acepolls&view=poll&id=' . $p->slug);
        }
        array_unshift($pList, JHTML::_('select.option', '', JText::_('COM_ACEPOLLS_SELECT_POLL'), 'url', 'title'));
        // dropdown output
        $lists = array();
        $lists['polls'] = JHTML::_('select.genericlist', $pList, 'id', 'class="inputbox" size="1" style="width:400px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"', 'url', 'title', JRoute::_('index.php?option=com_acepolls&view=poll&id=' . $poll->id . ':' . $poll->alias));
        //get the number of voters
        $voters = isset($options[0]) ? $options[0]->voters : 0;
        $num_of_options = count($options);
        for ($i = 0; $i < $num_of_options; $i++) {
            $vote =& $options[$i];
            //assign pie color to colors array
            $colors[$i] = $vote->color;
            //$links[$i]=$vote->link;
            if ($voters > 0) {
                $vote->percent = round(100 * $vote->hits / $voters, 1);
            } else {
                //if nobody has voted yet
                if ($params->get('show_what') == 1) {
                    $vote->percent = round(100 / $num_of_options, 1);
                } else {
                    $vote->percent = 0;
                }
            }
        }
        // show_what==1 because 1=show pie, 0=joomla default, 3 may be something else later
        //Pie chart
        // pass in two arrays, one of data, the other data labels
        $title_lenght = $params->get('title_lenght');
        foreach ($options as $vote_array) {
            //if show hits is true
            if ($params->get('show_hits')) {
                $hits = " (" . $vote_array->hits . ")";
            } else {
                $hits = '';
            }
            //if show options with zero votes is true
            if ($params->get('show_zero_votes')) {
                $text = JString::substr(html_entity_decode($vote_array->text, ENT_QUOTES, "utf-8"), 0, $title_lenght) . $hits;
                //$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text);
                $values[] = '
				"value":' . $vote_array->percent . ', 
				"label":"' . addslashes($text) . '", 
				"text":"' . addslashes($text) . '"
				';
            } else {
                //show only options that have hits
                if ($vote_array->percent) {
                    $text = JString::substr(html_entity_decode($vote_array->text, ENT_QUOTES, "utf-8"), 0, $title_lenght) . $hits;
                    //$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text);
                    $values[] = '
					"value":' . $vote_array->percent . ', 
					"label":"' . addslashes($text) . '", 
					"text":"' . addslashes($text) . '"
					';
                }
            }
        }
        // prepare the javascript for the pie
        //colors and values array to json
        //TODO use json_encode some day
        $json_colors = '["' . implode('", "', $colors) . '"]';
        $json_values = '[{' . implode('}, {', $values) . '}]';
        $js = '
        function ofc_ready() {}

        function open_flash_chart_data()
        {
        	return JSON.stringify(data);
        }

        var data = {
        "title":{
        	"text" : "",
        	"style" : "font-size: 14px; font-family: Verdana; text-align: center;"
        	},
        "bg_colour" : "#' . $params->get("bg_color") . '",
        "elements" :
            [{
            "type" : "pie",
            "tip" : "#label# \\n#val#%",
            "colours" : ' . $json_colors . ',
            "alpha" : ' . $params->get("opacity") . ',
            "start-angle" : ' . $params->get("start_angle") . ',
            "radius" : ' . $params->get("radius") . ',
            "no-labels" : ' . $params->get("no_labels") . ',
            "values" : ' . $json_values . ',
            "gradient-fill" : ' . $params->get("gradient") . ',
            "font-size" : ' . $params->get("font_size") . ',
            "label-colour" : "#' . $params->get("font_color") . '",
            "animate":[{
                "distance" : ' . $params->get("bounce_dinstance") . ',
                "type" : "' . $params->get("animation_type") . '"
        		}]
        	}]
        };
';
        //Check if the user has voted
        $cookieName = JUtility::getHash($this->mainframe->getName() . 'poll' . $poll_id);
        $cookieVoted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
        $query = "SELECT date FROM " . $db->nameQuote('#__acepolls_votes') . " WHERE poll_id=" . (int) $poll_id . " AND user_id=" . (int) $user->id;
        $db->setQuery($query);
        $userVoted = $db->loadResult() ? 1 : 0;
        $ip = ip2long($_SERVER['REMOTE_ADDR']);
        $query = "SELECT ip FROM " . $db->nameQuote('#__acepolls_votes') . " WHERE poll_id=" . (int) $poll_id . " AND ip = '" . $ip . "'";
        $db->setQuery($query);
        $ipVoted = $db->loadResult() ? 1 : 0;
        $date->setOffset($this->mainframe->getCfg('offset'));
        $now = $date->toFormat();
        //Algorithm for shoiwing or not the poll in the component
        if ($params->get('allow_voting')) {
            if ($now > $poll->publish_up && $now < $poll->publish_down) {
                if ($params->get('only_registered')) {
                    if (!$user->guest) {
                        if ($params->get('one_vote_per_user')) {
                            if ($userVoted) {
                                $allowToVote = 0;
                                $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
                            } else {
                                $allowToVote = 1;
                            }
                        } else {
                            if ($cookieVoted) {
                                $allowToVote = 0;
                                $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
                            } else {
                                $allowToVote = 1;
                            }
                        }
                    } else {
                        $allowToVote = 0;
                        $msg = JText::_('COM_ACEPOLLS_REGISTER_TO_VOTE');
                    }
                } else {
                    if ($cookieVoted) {
                        $allowToVote = 0;
                        $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
                    } else {
                        if ($params->get('ip_check')) {
                            if ($ipVoted) {
                                $allowToVote = 0;
                                $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
                            } else {
                                $allowToVote = 1;
                            }
                        } else {
                            $allowToVote = 1;
                        }
                    }
                }
            } else {
                $allowToVote = 0;
            }
            if ($now < $poll->publish_up) {
                $msg = JText::_('COM_ACEPOLLS_VOTE_NOT_STARTED');
            }
            if ($now > $poll->publish_down) {
                $msg = JText::_('COM_ACEPOLLS_VOTE_ENDED');
            }
        } else {
            $allowToVote = 0;
        }
        $this->assignRef('lists', $lists);
        $this->assignRef('params', $params);
        $this->assignRef('poll', $poll);
        $this->assignRef('options', $options);
        $this->assignRef('allowToVote', $allowToVote);
        $this->assignRef('msg', $msg);
        $this->assignRef('js', $js);
        parent::display($tpl);
    }