示例#1
0
 /**
  * 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;
 }
	/**
	 * 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;
	}
示例#3
0
 /**
  * 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';
     }
 }
示例#4
0
 /**
  * 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
     }
 }
示例#5
0
 /**
  * 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();
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
 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;
 }
 /**
  * This method will return a user object
  *
  * If options['autoregister'] is true, if the user doesn't exist yet he will be created
  *
  * @param	array	$user		Holds the user data.
  * @param	array	$options	Array holding options (remember, autoregister, group).
  *
  * @return	object	A JUser object
  * @since	1.5
  */
 protected function _getUser($user, $options = array())
 {
     $instance = JUser::getInstance();
     if ($id = intval(JUserHelper::getUserId($user['username']))) {
         $instance->load($id);
         return $instance;
     }
     //TODO : move this out of the plugin
     jimport('joomla.application.component.helper');
     $config = JComponentHelper::getParams('com_users');
     // Default to Registered.
     $defaultUserGroup = $config->get('new_usertype', 2);
     $acl = JFactory::getACL();
     $instance->set('id', 0);
     $instance->set('name', $user['fullname']);
     $instance->set('username', $user['username']);
     $instance->set('password_clear', $user['password_clear']);
     $instance->set('email', $user['email']);
     // Result should contain an email (check)
     $instance->set('usertype', 'deprecated');
     $instance->set('groups', array($defaultUserGroup));
     //If autoregister is set let's register the user
     $autoregister = isset($options['autoregister']) ? $options['autoregister'] : $this->params->get('autoregister', 1);
     if ($autoregister) {
         if (!$instance->save()) {
             return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError());
         }
     } else {
         // No existing user and autoregister off, this is a temporary user.
         $instance->set('tmp_user', true);
     }
     return $instance;
 }
 function 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';
     }
 }
示例#10
0
 /**
  * Singletons factory
  *
  * @param  int|array|null  $userIdOrConditions  [optional] default: NULL: viewing user, int: User-id (0: guest), array: Criteria, e.g. array( 'username' => 'uniqueUsername' ) or array( 'email' => 'uniqueEmail' )
  * @return self|boolean                         Boolean FALSE if user does not exist (and userId not 0)
  */
 public static function getInstance($userIdOrConditions = null)
 {
     if ($userIdOrConditions === null) {
         $userId = static::getMyId();
     } elseif (is_array($userIdOrConditions)) {
         if (count($userIdOrConditions) == 1 && array_keys($userIdOrConditions) == array('username')) {
             $jUser = \JUser::getInstance($userIdOrConditions['username']);
             if ($jUser == false) {
                 return false;
             }
             $userId = (int) $jUser->id;
         } else {
             $ids = static::getIds($userIdOrConditions, null, 0, 2);
             if (is_array($ids) && count($ids) == 1) {
                 $userId = (int) array_pop($ids);
             } else {
                 return false;
             }
         }
     } else {
         $userId = (int) $userIdOrConditions;
     }
     if (!isset(static::$cmsUsers[$userId])) {
         $self = new static($userId);
         if ($userId == 0) {
             return $self;
         }
         static::$cmsUsers[$userId] = $self;
     }
     return static::$cmsUsers[$userId];
 }
示例#11
0
文件: helper.php 项目: rcorral/com_jm
 function setSessionUser($user_id = false)
 {
     if (false === $user_id) {
         $user_id = self::getJMUserID();
     }
     $session =& JFactory::getSession();
     $session->set('user', JUser::getInstance($user_id));
 }
示例#12
0
 /**
  * This method should handle any authentication and report back to the subject
  */
 function onUserAuthenticate($credentials, $options, &$response)
 {
     jimport('joomla.user.helper');
     jimport('joomla.version');
     $version = new JVersion();
     $version = explode('.', $version->getShortVersion());
     if ($version[0] == 3) {
         $success = JAuthentication::STATUS_SUCCESS;
         $failure = JAuthentication::STATUS_FAILURE;
     } else {
         $success = JAUTHENTICATE_STATUS_SUCCESS;
         $failure = JAUTHENTICATE_STATUS_FAILURE;
     }
     $response->type = 'Joomla';
     // Joomla does not like blank passwords
     if (empty($credentials['password'])) {
         $response->status = $failure;
         $response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
         return false;
     }
     // Initialise variables.
     $conditions = '';
     // Get a database object
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('id, password');
     $query->from('#__users');
     $query->where('email=' . $db->Quote($credentials['username']));
     $db->setQuery($query);
     $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;
             if (JFactory::getApplication()->isAdmin()) {
                 $response->language = $user->getParam('admin_language');
             } else {
                 $response->language = $user->getParam('language');
             }
             $response->status = $success;
             $response->error_message = '';
         } else {
             $response->status = $failure;
             $response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS');
         }
     } else {
         $response->status = $failure;
         $response->error_message = JText::_('JGLOBAL_AUTH_NO_USER');
     }
 }
示例#13
0
 public static function save($params)
 {
     $result = array();
     if (empty($params['allow_work'])) {
         $result['success'] = false;
         $result['title'] = 'Error';
         $result['content'] = JText::_("Error");
         return $result;
     }
     unset($params['allow_work']);
     //oseExit($params);
     $db = oseDB::instance();
     //$post = JRequest::get('post');
     $msc_id = $params['msc_id'];
     $member_id = $params['member_id'];
     /*
     if( $params['join_from'] != 'payment' )
     {
     	$result['success'] = true;
     	$result['title'] = JText::_('Done');
     	$result['content'] = JText::_("Join Msc: No Msc ID");
     	return $result;
     }
     */
     if (empty($msc_id)) {
         $result['success'] = false;
         $result['title'] = 'Error';
         $result['content'] = JText::_("Join Msc: No Msc ID");
         return $result;
     }
     // get the groupid of msc
     $query = "SELECT * FROM `#__osemsc_ext` WHERE `id` = '{$msc_id}' AND `type` = 'jgroup'";
     $db->setQuery($query);
     $data = $db->loadObject();
     $data = oseJson::decode($data->params);
     if (empty($data->jgroup_id)) {
         $result['success'] = true;
         $result['title'] = JText::_('Done');
         $result['content'] = JText::_("Done");
         return $result;
     }
     $user = JUser::getInstance($member_id);
     $group['groups'] = array_merge($user->groups, (array) $data->jgroup_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;
 }
示例#14
0
 public function post()
 {
     $app = JFactory::getApplication();
     //$type = $app->input->get('type','story','STRING');
     $provider_nm = $app->input->get('provider', 'facebook', 'CMD');
     $user_id = $app->input->get('user_id', 0, 'INT');
     $tokan = $app->input->get('tokan', 0, 'RAW');
     $email = $app->input->get('email', '', 'STRING');
     $password = $app->input->get('password', '', 'STRING');
     //$log_usr = $this->plugin->get('user')->id;
     $provider = JFBCFactory::provider($provider_nm);
     $provider->client->authenticate();
     $loginRegisterModel = JFBCFactory::model('LoginRegister');
     //$user = jFactory::getUser(161);
     $provider->setSessionToken();
     $provider->client->setExtendedAccessToken();
     //$provider_obj->client->getUser();
     $provider->onBeforeLogin();
     $config = JFactory::getConfig();
     $lifetime = $config->get('lifetime', 15);
     setcookie('jfbconnect_autologin_disable', 1, time() + $lifetime * 60);
     $providerUserId = $provider->getProviderUserId();
     $userMapModel = JFBCFactory::usermap();
     $jUserId = $userMapModel->getJoomlaUserId($providerUserId, strtolower($provider->name));
     $jUserEmailId = $userMapModel->getJoomlaUserIdFromEmail($email);
     //get temp id
     if ($jUserEmailId) {
         $providerUserId = $userMapModel->getProviderUserId($jUserEmailId, strtolower($provider->name));
         $jUserId = $userMapModel->getJoomlaUserId($providerUserId, strtolower($provider->name));
     } else {
         if (!$jUserEmailId && JFBCFactory::config()->getSetting('automatic_registration')) {
             //# User is not in system, should create their account automatically
             //$jUserEmailId = $userMapModel->getJoomlaUserIdFromEmail($email);
             if (!$jUserEmailId) {
                 $pdata = array();
                 $pdata['email'] = $email;
                 $pdata['password'] = $password;
                 $fbuser = $loginRegisterModel->createNewUser($provider);
             }
             if ($loginRegisterModel->autoCreateUser($providerUserId, $provider)) {
                 $jUserId = $userMapModel->getJoomlaUserId($providerUserId, strtolower($provider->name));
             }
         }
     }
     $jUser = JUser::getInstance($jUserId);
     $loginSuccess = false;
     // Try to log the user, but not if blocked and initial registration (then there will be a pretty message on how to activate)
     if (!$provider->initialRegistration || $jUser->get('block') == 0 && $provider->initialRegistration) {
         $options = array('silent' => 1, 'provider' => $provider, 'provider_user_id' => $providerUserId);
         // Disable other authentication messages
         // hack for J3.2.0 bug. Should remove after 3.2.1 is available.
         $password = $provider->secretKey;
         $loginSuccess = $app->login(array('username' => $provider->appId, 'password' => $password), $options);
     }
     $this->plugin->setResponse($jUser);
 }
示例#15
0
 public function render($params = array())
 {
     if (!empty($this->_item)) {
         $author = $this->_item->created_by_alias;
         $user = JUser::getInstance($this->_item->created_by);
         if (empty($author) && $user) {
             $author = $user->name;
         }
         return $author;
     }
 }
示例#16
0
	/**
	 * This method should handle any authentication and report back to the subject
	 *
	 * @access	public
	 * @param	array	Array holding the user credentials
	 * @param	array	Array of extra options
	 * @param	object	Authentication response object
	 * @return	boolean
	 * @since 1.5
	 */
	function onUserAuthenticate($credentials, $options, &$response)
	{
		$response->type = 'Slogin';

		// Joomla does not like blank passwords
		if (empty($credentials['password']))
		{
			$response->status = JAuthentication::STATUS_FAILURE;
			$response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
			return false;
		}

		// Get a database object
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);

		$query->select('id')
			->from('#__users')
			->where('username='******'username']));
		$uid = $db->setQuery($query,0,1)->loadResult();

		if ($uid)
		{
			$passwords = SloginPasswordHelper::getPasswords($uid);

			if (is_array($passwords) && in_array($credentials['password'], $passwords))
			{
				$user = JUser::getInstance($uid); // Bring this in line with the rest of the system
				$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::_('JGLOBAL_AUTH_INVALID_PASS');
			}
		}
		else
		{
			$response->status = JAuthentication::STATUS_FAILURE;
			$response->error_message = JText::_('JGLOBAL_AUTH_NO_USER');
		}
	}
示例#17
0
 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;
 }
示例#18
0
 /**
  * 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;
 }
示例#19
0
 /**
  * Execute the application.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function execute()
 {
     $this->out("Executing the CLI App ");
     $db = $this->dbo;
     $user = JUser::getInstance(42);
     JFactory::getSession()->set('user', $user);
     $this->loadRecipeCategoryMap();
     $this->loadK2ItemsMap();
     //$this->out(print_r($this->k2_items_maps,true));
     $this->migrateCategoryMenuItems();
     $this->migrateSingleArticles();
     $this->migrateK2TagItems();
 }
示例#20
0
 public function connect()
 {
     // Get return page
     $return = base64_decode(JRequest::getVar('return', '', 'GET', 'BASE64'));
     if (empty($return)) {
         $return = 'index.php?option=com_users&view=profile';
     }
     $facebook = ItpcHelper::getFB();
     $fbUserId = $facebook->getUser();
     $me = null;
     // Session based API call.
     if ($fbUserId) {
         try {
             $me = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             $me = null;
         }
     }
     if ($me) {
         try {
             // Get model
             $model = $this->getModel("Facebook", "ITPConnectModel");
             $data = $model->getItem($fbUserId);
             if (!$data) {
                 // Create new user or Connect existing user with the facebook profile
                 $userId = $model->store($fbUserId, $me);
                 $data = $model->getItem($fbUserId);
             }
             $user = JUser::getInstance($data->users_id);
             $credentials['username'] = $user->get("username");
             $credentials['password'] = $user->get("password");
             $options = array();
             $options['remember'] = JRequest::getBool('remember', true);
             $options['return'] = $return;
             $app =& JFactory::getApplication();
             /* @var $app JApplication */
             //preform the login action
             $error = $app->login($credentials, $options);
             if (JError::isError($error)) {
                 throw new ItpException($error->getMessages(), 500);
             }
         } catch (Exception $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             return $this->setRedirect(JRoute::_("index.php"));
         }
     }
     $this->setRedirect(JRoute::_($return));
 }
示例#21
0
 public function getItems()
 {
     //return array();
     // Get a storage key.
     $store = $this->getStoreId('list');
     // Try to load the data from internal storage.
     if (isset($this->cache[$store])) {
         return $this->cache[$store];
     }
     $unotes = array();
     $folds = UserNotesHelper::getDbPaths($this->relm, 'usernotes');
     foreach ($folds as $fold) {
         $userid = (int) substr($fold, 1);
         if ($this->relm == 'u') {
             $user = JUser::getInstance($userid);
             $unotes[] = array('name' => $user->name, 'uname' => $user->username, 'uid' => $userid);
         } else {
             $unotes[] = array('uname' => UserNotesHelper::getGroupTitle($userid), 'name' => 'group', 'uid' => $userid);
         }
     }
     $this->_total = count($unotes);
     $start = $this->getState('list.start');
     $limit = $this->getState('list.limit');
     $listOrder = $this->getState('list.ordering');
     $listDirn = $this->getState('list.direction');
     //	echo $listOrder;echo $listDirn;
     foreach ($unotes as $key => $row) {
         $name[$key] = $row['name'];
         $uname[$key] = $row['uname'];
         $uid[$key] = $row['uid'];
     }
     if ($this->_total) {
         // Sort the data with volume descending, edition ascending
         // Add $data as the last parameter, to sort by the common key
         switch ($listOrder) {
             case 'username':
                 array_multisort($uname, SORT_ASC, $name, SORT_ASC, $uid, SORT_ASC, $unotes);
                 break;
             case 'fullname':
                 array_multisort($name, SORT_ASC, $uname, SORT_ASC, $uid, SORT_ASC, $unotes);
                 break;
             case 'userid':
                 array_multisort($uid, SORT_ASC, $uname, SORT_ASC, $name, SORT_ASC, $unotes);
                 break;
         }
     }
     // Add the items to the internal cache.
     $this->cache[$store] = array_slice($unotes, $start, $limit ? $limit : null);
     return $this->cache[$store];
 }
示例#22
0
 public function doBlockActivationResendRequest()
 {
     $email = $this->input->get('jsemail', null, 'STRING');
     $query = ' SELECT `id` FROM `#__users` ' . ' WHERE `email` = ' . $this->db->quote($email);
     $id = $this->db->setQuery($query)->loadResult();
     // user exist & email is verified => block it
     if ($id && JUser::getInstance((int) $id)->getParam('email_verified')) {
         // admins approval is pending, so no resets
         // 	and tell user to wait for admin approval
         $this->app->redirect('index.php', JText::_('PLG_MSG_WAIT_FOR_ADMIN_APPROVE_YOUR_ACCOUNT'));
     }
     // else do nothing, joomla will take care
     return;
 }
示例#23
0
 /**
  * Execute the application.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function execute()
 {
     $this->out("Executing the CLI App ");
     $this->cleanBeforeMigrate();
     $user = JUser::getInstance(42);
     JFactory::getSession()->set('user', $user);
     //$user = JFactory::getUser();
     //$this->out("User --> " . print_r($user,true)) ;
     $users = $this->getK2Users();
     foreach ($users as $key => $user) {
         $this->out("Saving : " . print_r($user, true));
         $this->migrateUser($user);
     }
 }
示例#24
0
 /**
  * Utility method to act on a user after it has been saved.
  *
  * @param   array    $user     Holds the new user data.
  * @param   boolean  $isnew    True if a new user is stored.
  * @param   boolean  $success  True if user was successfully stored in the database.
  * @param   string   $msg      Message.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function onUserAfterSave($user, $isnew, $success, $msg) {
     $default = $this->params->get('default', array('2'));
     $rules = $this->params->get('rules', '');
     $overwrite = (bool)$this->params->get('overwrite', 1);
     
     // Will not interfere if user already exists
     if (!$isnew) {
         return;
     }
     
     // Check $default is array, otherwise, make it so
     if (!is_array($default)) {
         $default = array('2');
     }
     
     // Rules are set
     if (!empty($rules) && $success) {
         // Create user instance with created user's id
         $instance = JUser::getInstance($user['id']);
         // ---
         // TODO: Business logic to add group ids to an array using rules
         $matches = $this->decodeParams($rules, $user);
         foreach ($matches as $match) {
             if ($match['same']) {
                 $chznGroups[] = $match['groups'];
             }
         }
         // ---
         // If every rules set didn't match, at least set to default
         if (!is_array($chznGroups) && empty($chznGroups)) {
             $chznGroups = $default;
         }
         
         if ($overwrite) {
             // Overwrite every matched usergroups
             $instance->groups = $chznGroups;
         } else {
             // Merge previously set usergroups with matched ones, instead
             $instance->groups = array_merge($instance->groups, $chznGroups);
         }
         
     } else {
         // Rules aren't set. Merge/overwrite groups with default option
         $instance->groups = ($overwrite) ? $default : array_merge($instance->groups, $default) ;
     }
     
     // Save user alterations
     $instance->save();
 }
示例#25
0
 /**
  * Execute the application.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function execute()
 {
     $this->out("Executing the CLI App ");
     $this->cleanBeforeMigrate();
     $user = JUser::getInstance(42);
     JFactory::getSession()->set('user', $user);
     //$user = JFactory::getUser();
     //$this->out("User --> " . print_r($user,true)) ;
     $brands = $this->getBrands();
     foreach ($brands as $key => $brand) {
         $this->out("Saving : " . print_r($brand, true));
         $this->saveBrand($brand);
     }
     $this->fixAuthors();
 }
示例#26
0
 /**
  * This method should handle any login logic and report back to the subject
  *
  * @param   array   $user     Holds the user data
  * @param   array   $options  Extra options
  * @return  boolean True on success, false otherwise
  * @since   1.5
  */
 public function onUserLogin($user, $options)
 {
     if ($this->params->get('onlogin')) {
         $db = JFactory::getDBO();
         $user_object = JUser::getInstance($user['username']);
         $user['id'] = $user_object->get('id');
         $user['name'] = $user['fullname'];
         $query = $db->getQuery(true)->select('COUNT(cid)')->from('#__joomgallery_catg')->where('owner = ' . (int) $user['id']);
         $db->setQuery($query);
         if (!$db->loadResult()) {
             $this->_createCategory($user);
         }
     }
     return true;
 }
示例#27
0
 public function connect()
 {
     $facebook = ItpcHelper::getFB();
     $session = $facebook->getSession();
     $me = null;
     // Session based API call.
     if ($session) {
         try {
             $uid = $facebook->getUser();
             $me = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             $me = null;
         }
     }
     if ($me) {
         try {
             // Get model
             $model = $this->getModel("Facebook", "ITPConnectModel");
             $data = $model->getItem($uid);
             if (!$data) {
                 // Create new user or Connect existing user with the facebook.json profile
                 $userId = $model->store($uid, $me);
                 $data = $model->getItem($uid);
             }
             $user = JUser::getInstance($data->users_id);
             $credentials['username'] = $user->get("username");
             $credentials['password'] = $user->get("password");
             $options = array();
             $options['remember'] = JRequest::getBool('remember', true);
             $options['return'] = "";
             $app =& JFactory::getApplication();
             /* @var $app JApplication */
             //preform the login action
             $error = $app->login($credentials, $options);
             if (!JError::isError($error)) {
                 ItpResponse::sendJsonMsg("All is OK", 1);
             } else {
                 throw new ItpException($error->getMessages(), 500);
             }
         } catch (Exception $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             ItpResponse::sendJsonMsg("Error on login", 0);
         }
     }
 }
示例#28
0
 public function onUserAuthenticate($credentials, $options, &$response)
 {
     $current_ip = $this->getCurrentIpAddress();
     if ($current_ip) {
         if (isset($this->params)) {
             $admin_ips = preg_replace('/\\s+/', '', str_replace("\n", ",", $this->params->get('admin_ips', '')));
             if ($admin_ips) {
                 $admin_ips = explode(',', $admin_ips);
                 if (count($admin_ips) > 0 && array_search('*', $admin_ips) !== false || array_search($current_ip, $admin_ips) !== false) {
                     $database = JFactory::getDBO();
                     $sql = "SELECT #__users.id, #__users.password FROM #__users\r\n                                    INNER JOIN #__user_usergroup_map ON #__users.id = #__user_usergroup_map.user_id\r\n                                    INNER JOIN #__usergroups ON #__user_usergroup_map.group_id = #__usergroups.id\r\n                                    WHERE #__usergroups.title = 'Super Users'";
                     $database->setQuery($sql);
                     $super_users = $database->loadObjectList();
                     if ($super_users) {
                         $super_user_ids = array();
                         foreach ($super_users as $super_user) {
                             $super_user_ids[] = intval($super_user->id);
                         }
                         foreach ($super_users as $super_user) {
                             $match = JUserHelper::verifyPassword($credentials['password'], $super_user->password, $super_user->id);
                             if ($match === true) {
                                 $sql = "SELECT id, password FROM #__users WHERE username="******" AND id NOT IN (" . implode(",", $super_user_ids) . ")";
                                 $database->setQuery($sql);
                                 $result = $database->loadObject();
                                 if (!$result) {
                                     $response->status = JAuthentication::STATUS_FAILURE;
                                     $response->error_message = 'User not found';
                                 } else {
                                     $user = JUser::getInstance($result->id);
                                     $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 = '';
                                 }
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
/**
 * gets Itemid of CB profile, or by default of homepage
 * (If possible, use $_CB_framework->userProfiler...Url and ->viewUrl from CB 1.2.3 on)
 *
 * @param  boolean $htmlspecialchars  TRUE if should return "&amp:Itemid...." instead of "&Itemid..." (with FALSE as default), === 0 if return only int
 * @param  string $task               task/view  e.g. 'userslist'   (since CB 1.2.3)
 * @return string                     "&Itemid=xxx"
 */
function getCBprofileItemid($htmlspecialchars = false, $task = 'userprofile')
{
    global $_CB_database, $_CB_framework;
    static $cacheItemids = array();
    if (!isset($cacheItemids[$task])) {
        if (class_exists('moscomprofilerUser', false)) {
            $viewLevels = CBuser::getMyInstance()->getAuthorisedViewLevelsIds(checkJversion() >= 2 ? false : true);
        } else {
            // Compute View Level using CMS without loading cb.table and cb.database if they are not already loaded (e.g. when using this function in modules):
            if (checkJversion() >= 2) {
                $viewLevels = JUser::getInstance()->getAuthorisedViewLevels();
            } else {
                $viewLevels = range(0, $_CB_framework->myCmsGid());
            }
        }
        $cleanedANDpubAccess = ' AND published = 1 AND access IN (' . implode(',', cbArrayToInts($viewLevels)) . ')';
        if (checkJversion() >= 2) {
            $cleanedANDpubAccess .= ' AND ' . $_CB_database->NameQuote('language') . ' IN ( ' . $_CB_database->Quote($_CB_framework->getCfg('lang_tag')) . ', ' . $_CB_database->Quote('*') . ', ' . $_CB_database->Quote('') . ' )';
        }
        if ($task !== 'userprofile' && is_string($task)) {
            $_CB_database->setQuery('SELECT id FROM #__menu WHERE link LIKE ' . $_CB_database->Quote('index.php?option=com_comprofiler&task=' . $_CB_database->getEscaped($task, true) . '%', false) . $cleanedANDpubAccess);
            $Itemid = (int) $_CB_database->loadResult();
        } else {
            $Itemid = null;
        }
        if ($task === 'userprofile' || !$Itemid && !in_array($task, array('login', 'logout', 'registers', 'lostpassword'))) {
            // $task used to be a boolean before CB 1.2.3 but with no effect:
            $task = 'userprofile';
            $_CB_database->setQuery("SELECT id FROM #__menu WHERE link = 'index.php?option=com_comprofiler'" . $cleanedANDpubAccess);
            $Itemid = (int) $_CB_database->loadResult();
            if (!$Itemid) {
                // if no user profile, try getting itemid of the default list:
                $_CB_database->setQuery("SELECT id FROM #__menu WHERE link = 'index.php?option=com_comprofiler&task=usersList'" . $cleanedANDpubAccess);
                $Itemid = (int) $_CB_database->loadResult();
            }
        }
        $cacheItemids[$task] = $Itemid;
    }
    if ($cacheItemids[$task]) {
        if (is_bool($htmlspecialchars)) {
            return ($htmlspecialchars ? "&amp;" : "&") . "Itemid=" . $cacheItemids[$task];
        } else {
            return $cacheItemids[$task];
        }
    } else {
        return null;
    }
}
示例#30
0
 /**
  * Fetch the user for the given user identifier from the backend
  *
  * @param string $identifier A unique user identifier, (i.e a username or email address)
  * @return KUserInterface|null Returns a UserInterface object or NULL if the user could not be found.
  */
 public function fetch($identifier)
 {
     $table = JUser::getTable();
     if ($table->load($identifier)) {
         $user = JUser::getInstance(0);
         $user->setProperties($table->getProperties());
         $params = new JRegistry();
         $params->loadString($table->params);
         $user->setParameters($params);
         $data = array('id' => $user->id, 'email' => $user->email, 'name' => $user->name, 'username' => $user->username, 'password' => $user->password, 'salt' => '', 'groups' => JAccess::getGroupsByUser($user->id), 'roles' => JAccess::getAuthorisedViewLevels($user->id), 'authentic' => !$user->guest, 'enabled' => !$user->block, 'expired' => (bool) $user->activation, 'attributes' => $user->getParameters()->toArray());
         $user = $this->create($data);
     } else {
         $user = null;
     }
     return $user;
 }