当前位置: 首页>>代码示例>>PHP>>正文


PHP JUser::set方法代码示例

本文整理汇总了PHP中JUser::set方法的典型用法代码示例。如果您正苦于以下问题:PHP JUser::set方法的具体用法?PHP JUser::set怎么用?PHP JUser::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JUser的用法示例。


在下文中一共展示了JUser::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: JUser

 static function create_joomla_user($user_info)
 {
     $usersConfig = JComponentHelper::getParams('com_users');
     $authorize = JFactory::getACL();
     $user = new JUser();
     // Initialize new usertype setting
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 'Registered';
     }
     // Bind the user_info array to the user object
     if (!$user->bind($user_info)) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     $user->set('usertype', $newUsertype);
     $system = 2;
     // ID of Registered
     $user->groups = array();
     $user->groups[] = $system;
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     $parent = JFactory::getUser();
     $user->setParam('u' . $parent->id . '_parent_id', $parent->id);
     if ($user_info['block']) {
         $user->set('block', '1');
     }
     // If there was an error with registration
     if (!$user->save()) {
         return false;
     }
     /* Update profile additional data */
     return JoomdleHelperMappings::save_user_info($user_info);
 }
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:35,代码来源:users.php

示例2: JUser

 function addUser16($values, $source = 'subscribe')
 {
     $config = EasyBlogHelper::getConfig();
     $usersConfig = JComponentHelper::getParams('com_users');
     $canRegister = $source == 'comment' ? $config->get('comment_registeroncomment', 0) : $config->get('main_registeronsubscribe', 0);
     if ($usersConfig->get('allowUserRegistration') == '0' || !$canRegister) {
         return JText::_('COM_EASYBLOG_REGISTRATION_DISABLED');
     }
     $username = $values['username'];
     $email = $values['email'];
     $fullname = $values['fullname'];
     $mainframe = JFactory::getApplication();
     $jConfig = EasyBlogHelper::getJConfig();
     $authorize = JFactory::getACL();
     $document = JFactory::getDocument();
     $user = new JUser();
     //$pathway 	      = & $mainframe->getPathway();
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 'Registered';
     }
     $pwdClear = $username . '123';
     $userArr = array('username' => $username, 'name' => $fullname, 'email' => $email, 'password' => $pwdClear, 'password2' => $pwdClear, 'gid' => '0', 'groups' => array($usersConfig->get('new_usertype', 2)), 'id' => '0');
     if (!$user->bind($userArr)) {
         return $user->getError();
     }
     //check if user require to activate the acct
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == '1') {
         jimport('joomla.user.helper');
         $user->set('activation', md5(JUserHelper::genRandomPassword()));
         $user->set('block', '1');
     }
     JPluginHelper::importPlugin('user');
     $user->save();
     // Send registration confirmation mail
     $password = $pwdClear;
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     //Disallow control chars in the email
     //load com_user language file
     $lang = JFactory::getLanguage();
     $lang->load('com_users');
     //UserController::_sendMail($user, $password);
     return $user->id;
 }
开发者ID:Tommar,项目名称:vino2,代码行数:45,代码来源:registration.php

示例3: JUser

 static function create_joomla_user($user_info)
 {
     $usersConfig = JComponentHelper::getParams('com_users');
     $authorize = JFactory::getACL();
     $user = new JUser();
     // Initialize new usertype setting
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 2;
     }
     // Password comes hashed
     // On bind, Joomla hashes it again, so we save it before
     $password = $user_info['password'];
     // Bind the user_info array to the user object
     if (!$user->bind($user_info)) {
         JError::raiseError(500, $user->getError());
     }
     // Manually set original hashed password
     $user->password = $password;
     // Set some initial user values
     $user->set('id', 0);
     $user->groups = array();
     $user->groups[] = $newUsertype;
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     $parent = JFactory::getUser();
     $user->setParam('u' . $parent->id . '_parent_id', $parent->id);
     if ($user_info['block']) {
         $user->set('block', '1');
     }
     // If there was an error with registration
     if (!$user->save()) {
         JError::raiseError(500, $user->getError());
         return false;
     }
     // Set password in crypted form
     //		$u = new JObject ();
     //		$u->id = $user->id;
     //		$u->password = $password;
     /* Update profile additional data */
     return JoomdleHelperMappings::save_user_info($user_info, false);
 }
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:42,代码来源:users.php

示例4: array

 function &getUserObject($user, $options = array())
 {
     JLoader::import('joomla.user.helper');
     $instance = new JUser();
     if ($id = intval(JUserHelper::getUserId($user['username']))) {
         $instance->load($id);
         return $instance;
     }
     JLoader::import('joomla.application.component.helper');
     $config = JComponentHelper::getParams('com_users');
     $defaultUserGroup = $config->get('new_usertype', 2);
     $acl = JFactory::getACL();
     $instance->set('id', 0);
     $instance->set('name', $user['fullname']);
     $instance->set('username', $user['username']);
     $instance->set('password_clear', $user['password_clear']);
     $instance->set('email', $user['email']);
     // Result should contain an email (check)
     $instance->set('usertype', 'deprecated');
     $instance->set('groups', array($defaultUserGroup));
     return $instance;
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:22,代码来源:nofesalogin.php

示例5: onBeforeRead

 /**
  * Use the slug instead of the id to read a record
  *
  * @return bool
  */
 public function onBeforeRead()
 {
     $this->getThisModel()->setIDsFromRequest();
     $id = $this->getThisModel()->getId();
     $slug = $this->input->getString('slug', null);
     if (!$id && $slug) {
         $records = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->slug($slug)->getItemList();
         if (!empty($records)) {
             $item = array_pop($records);
             $this->getThisModel()->setId($item->akeebasubs_level_id);
         }
     }
     $subid = $this->input->getInt('subid', 0);
     $subscription = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($subid)->getItem();
     // Working around Progressive Caching
     JFactory::getApplication()->input->set('subid', $subid);
     $this->registerUrlParams(array('subid' => 'INT'));
     $this->getThisView()->assign('subscription', $subscription);
     if ($subscription->akeebasubs_level_id) {
         $this->getThisModel()->setId($subscription->akeebasubs_level_id);
     }
     /**
      * Joomla! 1.6 and later - we have to effectively "re-login" the user,
      * otherwise his ACL privileges are stale.
      */
     // Get the current user's ID
     $userid = JFactory::getUser()->id;
     // Get a reference to Joomla!'s session object
     $session = JFactory::getSession();
     if (empty($userid)) {
         // Guest user; we'll have to log him in
         $userid = $subscription->user_id;
         // Is it the same user who initiated the subscription payment?
         $subscriber_user_id = $session->get('subscribes.user_id', null, 'com_akeebasubs');
         if ($subscriber_user_id == $subscription->user_id) {
             // Do not log him out; he's the user who initiated this subscription
             self::$loggedinUser = false;
             // Unset the subscriber user ID value
             $session->set('subscribes.user_id', null, 'com_akeebasubs');
         } else {
             // This is just someone who knows the URL. Let's log him out
             // after we're done showing the page.
             self::$loggedinUser = true;
         }
     } elseif ($userid == $subscription->user_id) {
         // User already logged in. We'll log him back in (due to Joomla!
         // ACLs not being applied otherwise) but we are not going to log him
         // back out.
         self::$loggedinUser = false;
     } elseif ($userid != $subscription->user_id) {
         // The logged in user doesn't match the subscription's user; deny access
         self::$loggedinUser = false;
         return false;
     }
     // This line returns an empty JUser object
     $newUserObject = new JUser();
     // This line FORCE RELOADS the user record.
     $newUserObject->load($userid);
     if ($newUserObject->id != $userid) {
         // The user cannot be found. Abort.
         self::$loggedinUser = false;
         return false;
     }
     // If it is a blocked user let's log him out after loading this page.
     // This decision is made no matter how we ended up deciding to log in
     // this user.
     if ($newUserObject->block) {
         self::$loggedinUser = true;
     }
     // Mark the user as logged in
     $newUserObject->block = 0;
     $newUserObject->set('guest', 0);
     // Register the needed session variables
     $session->set('user', $newUserObject);
     $db = JFactory::getDBO();
     // Check to see the the session already exists.
     $app = JFactory::getApplication();
     $app->checkSession();
     // Update the user related fields for the Joomla sessions table.
     $query = $db->getQuery(true)->update($db->qn('#__session'))->set(array($db->qn('guest') . ' = ' . $db->q($newUserObject->get('guest')), $db->qn('username') . ' = ' . $db->q($newUserObject->get('username')), $db->qn('userid') . ' = ' . (int) $newUserObject->get('id')))->where($db->qn('session_id') . ' = ' . $db->q($session->getId()));
     $db->setQuery($query);
     $db->execute();
     // Hit the user last visit field
     $newUserObject->setLastVisit();
     return true;
 }
开发者ID:jonatasmm,项目名称:akeebasubs,代码行数:91,代码来源:messages.php

示例6: apply

 public function apply()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $mainframe = JFactory::getApplication();
     $db = DiscussHelper::getDBO();
     $my = JFactory::getUser();
     $acl = JFactory::getACL();
     $config = DiscussHelper::getConfig();
     // Create a new JUser object
     $user = new JUser(JRequest::getVar('id', 0, 'post', 'int'));
     $original_gid = $user->get('gid');
     $post = JRequest::get('post');
     $user->name = $post['fullname'];
     if (DiscussHelper::getJoomlaVersion() >= '1.6') {
         $jformPost = JRequest::getVar('jform', array(), 'post', 'array');
         $post['params'] = $jformPost['params'];
     }
     if (!$user->bind($post)) {
         DiscussHelper::setMessageQueue($user->getError(), DISCUSS_QUEUE_ERROR);
         $this->_saveError($user->id);
     }
     if (DiscussHelper::getJoomlaVersion() >= '1.6') {
         if ($user->get('id') == $my->get('id') && $user->get('block') == 1) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_YOURSELF'), DISCUSS_QUEUE_ERROR);
             $this->_saveError($user->id);
         } else {
             if ($user->authorise('core.admin') && $user->get('block') == 1) {
                 DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_SUPERUSER'), DISCUSS_QUEUE_ERROR);
                 $this->_saveError($user->id);
             } else {
                 if ($user->authorise('core.admin') && !$my->authorise('core.admin')) {
                     DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_EDIT_SUPERUSER'), DISCUSS_QUEUE_ERROR);
                     $this->_saveError($user->id);
                 }
             }
         }
         //replacing thr group name with group id so it is save correctly into the Joomla group table.
         $jformPost = JRequest::getVar('jform', array(), 'post', 'array');
         if (!empty($jformPost['groups'])) {
             $user->groups = array();
             foreach ($jformPost['groups'] as $groupid) {
                 $user->groups[$groupid] = $groupid;
             }
         }
     } else {
         $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO');
         $groups = $acl->get_object_groups($objectID, 'ARO');
         $this_group = strtolower($acl->get_group_name($groups[0], 'ARO'));
         if ($user->get('id') == $my->get('id') && $user->get('block') == 1) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_YOURSELF'), DISCUSS_QUEUE_ERROR);
             $this->_saveError($user->id);
         } else {
             if ($this_group == 'super administrator' && $user->get('block') == 1) {
                 DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_SUPERUSER'), DISCUSS_QUEUE_ERROR);
                 $this->_saveError($user->id);
             } else {
                 if ($this_group == 'administrator' && $my->get('gid') == 24 && $user->get('block') == 1) {
                     DiscussHelper::setMessageQueue(JText::_('WARNBLOCK'), DISCUSS_QUEUE_ERROR);
                     $this->_saveError($user->id);
                 } else {
                     if ($this_group == 'super administrator' && $my->get('gid') != 25) {
                         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_EDIT_SUPERUSER'), DISCUSS_QUEUE_ERROR);
                         $this->_saveError($user->id);
                     }
                 }
             }
         }
     }
     // Are we dealing with a new user which we need to create?
     $isNew = $user->get('id') < 1;
     if (DiscussHelper::getJoomlaVersion() <= '1.5') {
         // do this step only for J1.5
         if (!$isNew) {
             // if group has been changed and where original group was a Super Admin
             if ($user->get('gid') != $original_gid && $original_gid == 25) {
                 // count number of active super admins
                 $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0';
                 $db->setQuery($query);
                 $count = $db->loadResult();
                 if ($count <= 1) {
                     DiscussHelper::setMessageQueue(JText::_('WARN_ONLY_SUPER'), DISCUSS_QUEUE_ERROR);
                     // disallow change if only one Super Admin exists
                     $this->setRedirect('index.php?option=com_easydiscuss&view=users');
                     return false;
                 }
             }
         }
     }
     /*
      * Lets save the JUser object
      */
     if (!$user->save()) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_SAVE_THE_USER_INFORMATION'), DISCUSS_QUEUE_ERROR);
         return $this->execute('edit');
     }
     // If updating self, load the new user object into the session
     if (DiscussHelper::getJoomlaVersion() <= '1.5') {
         // If updating self, load the new user object into the session
         if ($user->get('id') == $my->get('id')) {
//.........这里部分代码省略.........
开发者ID:BetterBetterBetter,项目名称:B3App,代码行数:101,代码来源:user.php

示例7: createUser

 public function createUser(&$tableModel)
 {
     jimport('joomla.mail.helper');
     $app =& JFactory::getApplication();
     $db =& JFactory::getDBO();
     $log =& JTable::getInstance('Log', 'Table');
     $log->id = null;
     $log->message = "";
     $log->referring_url = $_SERVER['HTTP_REFERER'];
     $log->message_type = 'plg.table.tablecsv.csv_import_user.information';
     $formModel =& $tableModel->getForm();
     $data =& $formModel->_formData;
     $clear_passwd = '';
     // grab username, name and email
     // @TODO - sanity check these config vars (plus userid) to make sure they have been edited.
     $userdata['username'] = $data[$this->username_element];
     $userdata['email'] = $data[$this->email_element];
     $userdata['name'] = $data[$this->name_element];
     if (!JMailHelper::isEmailAddress($userdata['email'])) {
         if ($app->isAdmin()) {
             $app->enqueueMessage("No email for {$userdata['username']}");
         }
         $log->message_type = 'plg.table.tablecsv.csv_import_user.warning';
         $log->message = "No email for {$userdata['username']}";
         $log->store();
         return false;
     }
     $db->setQuery("SELECT * FROM #__users WHERE username = " . $db->Quote($userdata['username']));
     $existing_user = $db->loadObject();
     if (!empty($existing_user)) {
         $user_id = $existing_user->id;
         $isNew = false;
     } else {
         $db->setQuery("SELECT * FROM #__users WHERE username != " . $db->Quote($userdata['username']) . " AND email = " . $db->Quote($userdata['email']));
         $existing_email = $db->loadObject();
         if (!empty($existing_email)) {
             if ($app->isAdmin()) {
                 $app->enqueueMessage("Email {$userdata['email']} for {$userdata['username']} already in use by {$existing_email->username}");
             }
             $log->message_type = 'plg.table.tablecsv.csv_import_user.warning';
             $log->message = "Email {$userdata['email']} for {$userdata['username']} already in use by {$existing_email->username}";
             $log->store();
             return false;
         }
         $user_id = 0;
         $isNew = true;
         if (!empty($this->password_element)) {
             $clear_passwd = $userdata['password'] = $userdata['password2'] = $data[$this->password_element];
             $data[$this->password_element] = '';
         } else {
             $clear_passwd = $userdata['password'] = $userdata['password2'] = $this->rand_str();
         }
     }
     $user = new JUser($user_id);
     $userdata['gid'] = 18;
     $userdata['block'] = 0;
     $userdata['id'] = $user_id;
     if ($isNew) {
         $now =& JFactory::getDate();
         $user->set('registerDate', $now->toMySQL());
     }
     if (!$user->bind($userdata)) {
         if ($app->isAdmin()) {
             $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
             $app->enqueueMessage($user->getError(), 'error');
         }
         $log->message_type = 'plg.table.tablecsv.csv_import_user.error';
         $log->message = "Error storing user info for: {$userdata['username']}";
         $log->store();
         return false;
     }
     if (!$user->save()) {
         if ($app->isAdmin()) {
             $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
             $app->enqueueMessage($user->getError(), 'error');
         }
         $log->message_type = 'plg.table.tablecsv.csv_import_user.error';
         $log->message = "Error storing user info for: {$userdata['username']}";
         $log->store();
         return false;
     }
     // save clear text password if requested
     if ($isNew && !empty($this->first_password_element)) {
         $data[$this->first_password_element] = $clear_passwd;
     }
     // store the userid
     $data[$this->userid_element] = $user->get('id');
     // optionally set 'created' flag
     if (!empty($this->user_created_element)) {
         $data[$this->user_created_element] = $this->user_created_value;
     }
     if ($isNew) {
         $log->message = "Created user: {$userdata['username']}";
     } else {
         $log->message = "Modified user: {$userdata['username']}";
     }
     $log->store();
     return true;
 }
开发者ID:nikshade,项目名称:fabrik21,代码行数:99,代码来源:csv_import_user_class.php

示例8: loginUser

 /**
  * Log in a user if necessary
  *
  * @return  boolean  True if a user was logged in
  */
 public function loginUser()
 {
     // No need to log in a user if the user is already logged in
     if (!$this->container->platform->getUser()->guest) {
         return false;
     }
     // This is Joomla!'s login and user helpers
     \JPluginHelper::importPlugin('user');
     JLoader::import('joomla.user.helper');
     // Get the query parameters
     $dlid = $this->input->getString('dlid', null);
     $credentials = array();
     $credentials['username'] = $this->input->getUsername('username', '');
     $credentials['password'] = $this->input->get('password', '', 'raw', 3);
     // Initialise
     $user_id = 0;
     // First attempt to log in by download ID
     if (!empty($dlid)) {
         try {
             $user_id = Filter::getUserFromDownloadID($dlid)->id;
         } catch (\Exception $exc) {
             $user_id = 0;
         }
     }
     // If the dlid failed, used he legacy username/password pair
     if ($user_id === 0 && !empty($credentials['username']) && !empty($credentials['password'])) {
         \JLoader::import('joomla.user.authentication');
         $options = array('remember' => false);
         $authenticate = \JAuthentication::getInstance();
         $response = $authenticate->authenticate($credentials, $options);
         if ($response->status == \JAuthentication::STATUS_SUCCESS) {
             $user_id = \JUserHelper::getUserId($response->username);
         }
     }
     // Log in the user
     if ($user_id !== 0) {
         // Mark the user login so we can log him out later on
         $this->haveLoggedInAUser = true;
         // This line returns an empty JUser object
         $newUserObject = new \JUser();
         // This line FORCE RELOADS the user record.
         $newUserObject->load($user_id);
         // Mark the user as logged in
         $newUserObject->block = 0;
         $newUserObject->set('guest', 0);
         // Register the needed session variables
         $session = \JFactory::getSession();
         $session->set('user', $newUserObject);
         $db = $this->container->db;
         // Check to see the the session already exists.
         $app = \JFactory::getApplication();
         $app->checkSession();
         // Update the user related fields for the Joomla sessions table.
         $query = $db->getQuery(true)->update($db->qn('#__session'))->set(array($db->qn('guest') . ' = ' . $db->q($newUserObject->get('guest')), $db->qn('username') . ' = ' . $db->q($newUserObject->get('username')), $db->qn('userid') . ' = ' . (int) $newUserObject->get('id')))->where($db->qn('session_id') . ' = ' . $db->q($session->getId()));
         $db->setQuery($query);
         $db->execute();
         // Hit the user last visit field
         $newUserObject->setLastVisit();
     }
     return $this->haveLoggedInAUser;
 }
开发者ID:,项目名称:,代码行数:66,代码来源:

示例9: onUserLoad

 /**
  * Event onUserLoad
  *
  * @param JUser $user
  *
  * @return bool
  */
 public function onUserLoad($user)
 {
     if (empty($user) || empty($user->id)) {
         return false;
     }
     try {
         $fields = $this->getFields($user->id);
     } catch (Exception $e) {
         $this->_subject->setError($e->getMessage());
         return false;
     }
     foreach ($fields as $field) {
         $fieldName = str_replace('magebridgefirstlast.', '', $field[0]);
         $fieldValue = $field[1];
         $user->set($fieldName, $fieldValue);
     }
 }
开发者ID:apiceweb,项目名称:MageBridgeCore,代码行数:24,代码来源:magebridgefirstlast.php

示例10: array

	function &_getUser($user, $options = array())
	{
		$instance = new JUser();
		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' );
		$usertype = $config->get( 'new_usertype', 'Registered' );

		$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( 'gid'			, $acl->get_group_id( '', $usertype));
		$instance->set( 'usertype'		, $usertype );

		//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;
	}
开发者ID:rhotog,项目名称:myApi,代码行数:38,代码来源:myapiuser.php

示例11: storeVM25

 /**
  * Bind the post data to the JUser object and the VM tables, then saves it
  * It is used to register new users
  * This function can also change already registered users, this is important when a registered user changes his email within the checkout.
  *
  * @author Max Milbers
  * @author Oscar van Eijk
  * @return boolean True is the save was successful, false otherwise.
  */
 public static function storeVM25(&$data, $checkToken = TRUE, &$userModel, $opc_no_activation = false, &$opc)
 {
     $message = '';
     $user = '';
     $newId = 0;
     if ($checkToken) {
         JRequest::checkToken() or jexit('Invalid Token, while trying to save user');
     }
     $mainframe = JFactory::getApplication();
     if (empty($data)) {
         vmError('Developer notice, no data to store for user');
         return false;
     }
     //To find out, if we have to register a new user, we take a look on the id of the usermodel object.
     //The constructor sets automatically the right id.
     $user = JFactory::getUser();
     $user_id = $user->id;
     $new = $user->id < 1;
     if (empty($user_id)) {
         $user = new JUser();
         //thealmega http://forum.virtuemart.net/index.php?topic=99755.msg393758#msg393758
     } else {
         $user = JFactory::getUser($user_id);
     }
     $gid = $user->get('gid');
     // Save original gid
     // Preformat and control user datas by plugin
     JPluginHelper::importPlugin('vmuserfield');
     $dispatcher = JDispatcher::getInstance();
     $valid = true;
     $dispatcher->trigger('plgVmOnBeforeUserfieldDataSave', array(&$valid, $user_id, &$data, $user));
     // $valid must be false if plugin detect an error
     if ($valid == false) {
         return false;
     }
     // Before I used this "if($cart && !$new)"
     // This construction is necessary, because this function is used to register a new JUser, so we need all the JUser data in $data.
     // On the other hand this function is also used just for updating JUser data, like the email for the BT address. In this case the
     // name, username, password and so on is already stored in the JUser and dont need to be entered again.
     if (empty($data['email'])) {
         $email = $user->get('email');
         if (!empty($email)) {
             $data['email'] = $email;
         }
     }
     $data['email'] = str_replace(array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $data['email']);
     unset($data['isRoot']);
     unset($data['groups']);
     unset($data['_authGroups']);
     //This is important, when a user changes his email address from the cart,
     //that means using view user layout edit_address (which is called from the cart)
     $user->set('email', $data['email']);
     if (empty($data['name'])) {
         $name = $user->get('name');
         if (!empty($name)) {
             $data['name'] = $name;
         }
     }
     if (empty($data['name'])) {
         $data['name'] = '';
         if (!empty($data['first_name'])) {
             $data['name'] = $data['first_name'];
         }
         if ($data['name'] == '_') {
             $data['name'] = '';
         }
         if (!empty($data['last_name'])) {
             $data['name'] = $data['last_name'];
         }
         if ($data['name'] == '_') {
             $data['name'] = '';
         }
         if (empty($data['name'])) {
             $data['name'] = $data['username'];
         }
         if ($data['name'] == '_') {
             $data['name'] = '';
         }
         if (empty($data['name'])) {
             $data['name'] = $data['email'];
         }
     }
     if (empty($data['username'])) {
         $username = $user->get('username');
         if (!empty($username)) {
             $data['username'] = $username;
         } else {
             $data['username'] = JRequest::getVar('username', '', 'post', 'username');
             if (empty($data['username'])) {
                 $data['username'] = $data['email'];
             }
//.........这里部分代码省略.........
开发者ID:aldegtyarev,项目名称:stelsvelo,代码行数:101,代码来源:user.php

示例12: saveUser

 function saveUser($auth_info)
 {
     // process the auth_info response
     if ($auth_info['stat'] == 'ok') {
         $db =& JFactory::getDBO();
         $rpxid = 'rpx' . md5($auth_info['profile']['identifier']);
         $query = "SELECT userid FROM #__rpx_mapping WHERE rpxid='" . $rpxid . "'";
         $db->setQuery($query);
         $userid = $db->loadResult();
         $newuser = true;
         if (isset($userid)) {
             $user =& JFactory::getUser($userid);
             if ($user->id == $userid) {
                 $newuser = false;
             } else {
                 // possible if previous registered, but meanwhile removed
                 // we have a userid without user...remove from the rpx_mapping
                 $query = "DELETE FROM #__rpx_mapping WHERE userid='" . $userid . "'";
                 $db->setQuery($query);
                 $db->query();
             }
         }
         if ($newuser == true) {
             // save the user
             $user = new JUser();
             $authorize =& JFactory::getACL();
             $newUsertype = 'Registered';
             $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 (isset($auth_info['profile']['displayName'])) {
                 $displayName = $auth_info['profile']['displayName'];
             } else {
                 if (isset($auth_info['profile']['name']['displayName'])) {
                     $displayName = $auth_info['profile']['name']['displayName'];
                 }
             }
             if (isset($auth_info['profile']['preferredUsername'])) {
                 $preferredUsername = $auth_info['profile']['preferredUsername'];
             } else {
                 if (isset($auth_info['profile']['name']['preferredUsername'])) {
                     $preferredUsername = $auth_info['profile']['name']['preferredUsername'];
                 }
             }
             $user->set('name', $displayName);
             // if username already exists, just add an index to it
             $nameexists = true;
             $index = 0;
             $userName = $preferredUsername;
             while ($nameexists == true) {
                 if (JUserHelper::getUserId($userName) != 0) {
                     $index++;
                     $userName = $preferredUsername . $index;
                 } else {
                     $nameexists = false;
                 }
             }
             $user->set('username', $userName);
             $host = JFactory::getURI()->getHost();
             $domain = substr($host, 4);
             // strips the www.
             if ($this->params->get('fakemail') == 0) {
                 if (isset($auth_info['profile']['email'])) {
                     $user->set('email', $auth_info['profile']['email']);
                 } else {
                     if (isset($auth_info['profile']['name']['email'])) {
                         $user->set('email', $auth_info['profile']['email']);
                     } else {
                         $user->set('email', str_replace(" ", "_", $userName) . "@" . $domain);
                     }
                 }
             } else {
                 $user->set('email', str_replace(" ", "_", $userName) . "@" . $domain);
             }
             $pwd = JUserHelper::genRandomPassword();
             $user->set('password', $pwd);
             if (!$user->save()) {
                 echo "ERROR: ";
                 echo $user->getError();
             } else {
                 $query = "INSERT INTO #__rpx_mapping (userid, rpxid) VALUES ('" . $user->get('id') . "','" . $rpxid . "')";
                 $db->setQuery($query);
                 if (!$db->query()) {
                     JERROR::raiseError(500, $db->stderror());
                 }
             }
             // check if the community builder tables are there
             $query = "SHOW TABLES LIKE '%__comprofiler'";
             $db->setQuery($query);
             $tableexists = $db->loadResult();
             if (isset($tableexists)) {
                 $cbquery = "INSERT IGNORE INTO #__comprofiler(id,user_id) VALUES ('" . $user->get('id') . "','" . $user->get('id') . "')";
                 $db->setQuery($cbquery);
                 if (!$db->query()) {
                     JERROR::raiseError(500, $db->stderror());
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:jomsocial,项目名称:JSVoice,代码行数:101,代码来源:rpx.php

示例13: onBeforeStore


//.........这里部分代码省略.........
     if ($data['gid'] === 0) {
         $data['gid'] = $defaultGroup;
     }
     $user->groups = (array) $data['gid'];
     if ($params->get('juser_field_block') != '') {
         $this->blockfield = $this->getFieldName($params, 'juser_field_block');
         $blocked = JArrayHelper::getValue($formModel->_formData, $this->blockfield, '');
         if (is_array($blocked)) {
             // probably a dropdown
             $data['block'] = (int) $blocked[0];
         } else {
             $data['block'] = (int) $blocked;
         }
     } else {
         $data['block'] = 0;
     }
     //$$$tom get password field to use in $origdata object if editing user and not changing password
     $origdata = $formModel->_origData;
     $pwfield = $this->passwordfield;
     $data['username'] = $this->usernamevalue;
     $data['password'] = $this->passwordvalue;
     $data['password2'] = $this->passwordvalue;
     $data['name'] = $this->namevalue;
     $name = $this->namevalue;
     $data['email'] = $this->emailvalue;
     $ok = $this->check($data, $formModel, $params);
     if (!$ok) {
         // @TODO - add some error reporting
         return false;
     }
     // Set the registration timestamp
     if ($isNew) {
         $now = JFactory::getDate();
         $user->set('registerDate', $now->toSql());
     }
     if ($isNew) {
         // If user activation is turned on, we need to set the activation information
         $useractivation = $usersConfig->get('useractivation');
         if ($useractivation == '1' && !$bypassActivation) {
             jimport('joomla.user.helper');
             $data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword());
             $data['block'] = 1;
         }
     }
     // Check that username is not greater than 150 characters
     $username = $data['username'];
     if (strlen($username) > 150) {
         $username = substr($username, 0, 150);
         $user->set('username', $username);
     }
     // Check that password is not greater than 100 characters
     if (strlen($data['password']) > 100) {
         $data['password'] = substr($data['password'], 0, 100);
     }
     // end new
     if (!$user->bind($data)) {
         $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
         return false;
     }
     /*
      * Lets save the JUser object
      */
     if (!$user->save()) {
         $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
开发者ID:rhotog,项目名称:fabrik,代码行数:67,代码来源:juser.php

示例14: storeUser_bk

 public function storeUser_bk($post)
 {
     $app = JFactory::getApplication();
     $redshopMail = new redshopMail();
     // Start data into user table
     // Initialize some variables
     $db = JFactory::getDbo();
     $me = JFactory::getUser();
     $acl = JFactory::getACL();
     // Create a new JUser object
     $user = new JUser($post['id']);
     $original_gid = $user->get('gid');
     $post['name'] = isset($post['name']) ? $post['name'] : $post['username'];
     // Changed for shipping code moved out of condition
     if (!$user->bind($post)) {
         $app->enqueueMessage(JText::_('COM_REDSHOP_CANNOT_SAVE_THE_USER_INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
         return false;
     }
     $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO');
     $groups = $acl->get_object_groups($objectID, 'ARO');
     $this_group = strtolower($acl->get_group_name($groups[0], 'ARO'));
     if ($user->get('id') == $me->get('id') && $user->get('block') == 1) {
         $msg = JText::_('COM_REDSHOP_YOU_CANNOT_BLOCK_YOURSELF');
         $app->enqueueMessage($msg, 'message');
         return false;
     } elseif ($this_group == 'super administrator' && $user->get('block') == 1) {
         $msg = JText::_('COM_REDSHOP_YOU_CANNOT_BLOCK_A_SUPER_ADMINISTRATOR');
         $app->enqueueMessage($msg, 'message');
         return false;
     } elseif ($this_group == 'administrator' && $me->get('gid') == 24 && $user->get('block') == 1) {
         $msg = JText::_('COM_REDSHOP_WARNBLOCK');
         $app->enqueueMessage($msg, 'message');
         return false;
     } elseif ($this_group == 'super administrator' && $me->get('gid') != 25) {
         $msg = JText::_('COM_REDSHOP_YOU_CANNOT_EDIT_A_SUPER_ADMINISTRATOR_ACCOUNT');
         $app->enqueueMessage($msg, 'message');
         return false;
     }
     // Are we dealing with a new user which we need to create?
     $isNew = $user->get('id') < 1;
     if (!$isNew) {
         // If group has been changed and where original group was a Super Admin
         if ($user->get('gid') != $original_gid && $original_gid == 25) {
             // Count number of active super admins
             $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0';
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count <= 1) {
                 // Disallow change if only one Super Admin exists
                 $this->setRedirect('index.php?option=' . $option . '&view=user', JText::_('COM_REDSHOP_WARN_ONLY_SUPER'));
                 return false;
             }
         }
     }
     /*
      * Lets save the JUser object
      */
     if (!$user->save()) {
         $app->enqueueMessage(JText::_('COM_REDSHOP_CANNOT_SAVE_THE_USER_INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
         return false;
     }
     /*
      * Time for the email magic so get ready to sprinkle the magic dust...
      */
     if ($isNew) {
         $redshopMail->sendRegistrationMail($post);
     }
     // If updating self, load the new user object into the session
     if ($user->get('id') == $me->get('id')) {
         // Get an ACL object
         $acl = JFactory::getACL();
         // Get the user group from the ACL
         $grp = $acl->getAroGroup($user->get('id'));
         // Mark the user as logged in
         $user->set('guest', 0);
         $user->set('aid', 1);
         // Fudge Authors, Editors, Publishers and Super Administrators into the special access group
         if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) {
             $user->set('aid', 2);
         }
         // Set the usertype based on the ACL group name
         $user->set('usertype', $grp->name);
         $session = JFactory::getSession();
         $session->set('user', $user);
     }
     // End data into user table
     return $user;
 }
开发者ID:jaanusnurmoja,项目名称:redjoomla,代码行数:90,代码来源:user_detail.php

示例15: createUser

 public function createUser(&$listModel)
 {
     // Include the JLog class.
     jimport('joomla.log.log');
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $logMessageType = 'plg.list.listcsv.csv_import_user.information';
     $formModel = $listModel->getFormModel();
     $data = $formModel->formData;
     $clear_passwd = '';
     // Load in the com_user language file
     $lang = JFactory::getLanguage();
     $lang->load('com_user');
     // Grab username, name and email
     // @TODO - sanity check these config vars (plus userid) to make sure they have been edited.
     $userdata['username'] = $data[$this->username_element];
     $userdata['email'] = $data[$this->email_element];
     $userdata['name'] = $data[$this->name_element];
     if (!FabrikWorker::isEmail($userdata['email'])) {
         if ($app->isAdmin()) {
             $app->enqueueMessage("No email for {$userdata['username']}");
         }
         JLog::add('No email for ' . $userdata['username'], JLog::NOTICE, $logMessageType);
         return false;
     }
     $query->select('*')->from('#__users')->where('username = ' . $db->quote($userdata['username']));
     $db->setQuery($query);
     $existing_user = $db->loadObject();
     if (!empty($existing_user)) {
         $user_id = $existing_user->id;
         $isNew = false;
     } else {
         $query->clear();
         $query->select('*')->from('#__users')->where('username != ' . $db->quote($userdata['username']) . ' AND email = ' . $db->quote($userdata['email']));
         $db->setQuery($query);
         $existing_email = $db->loadObject();
         if (!empty($existing_email)) {
             $msg = 'Email ' . $userdata['email'] . ' for ' . $userdata['username'] . ' already in use by ' . $existing_email->username;
             if ($app->isAdmin()) {
                 $app->enqueueMessage($msg);
             }
             JLog::add($msg, JLog::NOTICE, $logMessageType);
             return false;
         }
         $user_id = 0;
         $isNew = true;
         if (!empty($this->password_element)) {
             $clear_passwd = $userdata['password'] = $userdata['password2'] = $data[$this->password_element];
             $data[$this->password_element] = '';
         } else {
             $clear_passwd = $userdata['password'] = $userdata['password2'] = $this->rand_str();
         }
     }
     $user = new JUser($user_id);
     // $userdata['gid'] = 18;
     $userdata['block'] = 0;
     $userdata['id'] = $user_id;
     if ($isNew) {
         $now = JFactory::getDate();
         $user->set('registerDate', $now->toSql());
     }
     if (!$user->bind($userdata)) {
         if ($app->isAdmin()) {
             $app->enqueueMessage(FText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
             $app->enqueueMessage($user->getError(), 'error');
         }
         JLog::add('Error binding user info for: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
         return false;
     }
     if (!$user->save()) {
         if ($app->isAdmin()) {
             $app->enqueueMessage(FText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
             $app->enqueueMessage($user->getError(), 'error');
         }
         JLog::add('Error storing user info for: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
         return false;
     }
     // Save clear text password if requested
     if ($isNew && !empty($this->first_password_element)) {
         $data[$this->first_password_element] = $clear_passwd;
     }
     // Store the userid
     $data[$this->userid_element] = $user->get('id');
     // Optionally set 'created' flag
     if (!empty($this->user_created_element)) {
         $data[$this->user_created_element] = $this->user_created_value;
     }
     if ($isNew) {
         JLog::add('Created user: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
     } else {
         JLog::add('Modified user: ' . $userdata['username'], JLog::NOTICE, $logMessageType);
     }
     return true;
 }
开发者ID:jfquestiaux,项目名称:fabrik,代码行数:95,代码来源:csv_import_user_class.php


注:本文中的JUser::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。