本文整理汇总了PHP中JUser::save方法的典型用法代码示例。如果您正苦于以下问题:PHP JUser::save方法的具体用法?PHP JUser::save怎么用?PHP JUser::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUser
的用法示例。
在下文中一共展示了JUser::save方法的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);
}
示例2: addUserToGroup
/**
* Method to add a user to a group.
*
* @param integer $userId The id of the user.
* @param integer $groupId The id of the group.
*
* @return boolean True on success
*
* @since 11.1
* @throws RuntimeException
*/
public static function addUserToGroup($userId, $groupId)
{
// Get the user object.
$user = new JUser((int) $userId);
// Add the user to the group if necessary.
if (!in_array($groupId, $user->groups)) {
// Get the title of the group.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('title'));
$query->from($db->quoteName('#__usergroups'));
$query->where($db->quoteName('id') . ' = ' . (int) $groupId);
$db->setQuery($query);
$title = $db->loadResult();
// If the group does not exist, return an exception.
if (!$title) {
throw new RuntimeException('Access Usergroup Invalid');
}
// Add the group data to the user object.
$user->groups[$title] = $groupId;
// Store the user object.
$user->save();
}
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId) {
$temp->groups = $user->groups;
}
return true;
}
示例3: onMembershipActive
/**
* Run when a membership activated
* @param PlanOsMembership $row
*/
function onMembershipActive($row)
{
if (!$row->user_id && $row->username && $row->user_password) {
//Need to create the account here
$data['name'] = trim($row->first_name . ' ' . $row->last_name);
//Decrypt the password
$data['username'] = $row->username;
//Password
$privateKey = md5(JFactory::getConfig()->get('secret'));
$key = new JCryptKey('simple', $privateKey, $privateKey);
$crypt = new JCrypt(new JCryptCipherSimple(), $key);
$data['password'] = $data['password2'] = $data['password'] = $crypt->decrypt($row->user_password);
$data['email1'] = $data['email2'] = $data['email'] = $row->email;
$params = JComponentHelper::getParams('com_users');
$data['groups'] = array();
$data['groups'][] = $params->get('new_usertype', 2);
$user = new JUser();
if (!$user->bind($data)) {
return false;
}
// Store the data.
if (!$user->save()) {
return false;
}
$row->user_id = $user->get('id');
$row->store();
}
}
示例4: addUserToGroup
/**
* Method to add a user to a group.
*
* @param integer $userId The id of the user.
* @param integer $groupId The id of the group.
*
* @return mixed Boolean true on success, JException on error.
* @since 11.1
*/
public static function addUserToGroup($userId, $groupId)
{
// Get the user object.
$user = new JUser((int) $userId);
// Add the user to the group if necessary.
if (!in_array($groupId, $user->groups)) {
// Get the title of the group.
$db = JFactory::getDbo();
$db->setQuery('SELECT title' . ' FROM #__usergroups' . ' WHERE id = ' . (int) $groupId);
$title = $db->loadResult();
// Check for a database error.
if ($db->getErrorNum()) {
return new JException($db->getErrorMsg());
}
// If the group does not exist, return an exception.
if (!$title) {
return new JException(JText::_('JLIB_USER_EXCEPTION_ACCESS_USERGROUP_INVALID'));
}
// Add the group data to the user object.
$user->groups[$title] = $groupId;
// Store the user object.
if (!$user->save()) {
return new JException($user->getError());
}
}
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId) {
$temp->groups = $user->groups;
}
return true;
}
示例5: onAKPaymentNew
/**
* Returns the payment form to be submitted by the user's browser. The form must have an ID of
* "paymentForm" and a visible submit button.
*
* @param string $paymentmethod
* @param JUser $user
* @param AkeebasubsTableLevel $level
* @param AkeebasubsTableSubscription $subscription
* @return string
*/
public function onAKPaymentNew($paymentmethod, $user, $level, $subscription)
{
if ($paymentmethod != $this->ppName) {
return false;
}
// Set the payment status to Pending
$oSub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($subscription->akeebasubs_subscription_id)->getItem();
$updates = array('state' => 'P', 'enabled' => 0, 'processor_key' => md5(time()));
$oSub->save($updates);
// Activate the user account, if the option is selected
$activate = $this->params->get('activate', 0);
if ($activate && $user->block) {
$updates = array('block' => 0, 'activation' => '');
$user->bind($updates);
$user->save($updates);
}
// Render the HTML form
$nameParts = explode(' ', $user->name, 2);
$firstName = $nameParts[0];
if (count($nameParts) > 1) {
$lastName = $nameParts[1];
} else {
$lastName = '';
}
$html = $this->params->get('instructions', '');
if (empty($html)) {
$html = <<<ENDTEMPLATE
<p>Dear Sir/Madam,<br/>
In order to complete your payment, please deposit {AMOUNT}€ to our bank account:</p>
<p>
<b>IBAN</b>: XX00.000000.00000000.00000000<br/>
<b>BIC</b>: XXXXXXXX
</p>
<p>Please reference subscription code {SUBSCRIPTION} in your payment. Make sure that any bank charges are paid by you in full and not deducted from the transferred amount. If you're using e-Banking to transfer the funds, please select the "OUR" bank expenses option.</p>
<p>Thank you in advance,<br/>
The management</p>
ENDTEMPLATE;
}
$html = str_replace('{AMOUNT}', sprintf('%01.02f', $subscription->gross_amount), $html);
$html = str_replace('{SUBSCRIPTION}', sprintf('%06u', $subscription->akeebasubs_subscription_id), $html);
$html = str_replace('{FIRSTNAME}', $firstName, $html);
$html = str_replace('{LASTNAME}', $lastName, $html);
$html = str_replace('{LEVEL}', $level->title, $html);
// Get a preloaded mailer
$mailer = AkeebasubsHelperEmail::getPreloadedMailer($subscription, 'plg_akeebasubs_subscriptionemails_offline');
// Replace custom [INSTRUCTIONS] tag
$body = str_replace('[INSTRUCTIONS]', $html, $mailer->Body);
$mailer->setBody($body);
if ($mailer !== false) {
$mailer->addRecipient($user->email);
$result = $mailer->Send();
$mailer = null;
}
@(include_once JPATH_SITE . '/components/com_akeebasubs/helpers/message.php');
if (class_exists('AkeebasubsHelperMessage')) {
$html = AkeebasubsHelperMessage::processLanguage($html);
}
$html = '<div>' . $html . '</div>';
return $html;
}
示例6: createNewUser
public function createNewUser($params)
{
$user = new JUser(0);
JLoader::import('joomla.application.component.helper');
$usersConfig = JComponentHelper::getParams('com_users');
$newUsertype = $usersConfig->get('new_usertype');
// get the New User Group from com_users' settings
if (empty($newUsertype)) {
$newUsertype = 2;
}
$params['groups'] = array($newUsertype);
$params['sendEmail'] = 0;
// Set the user's default language to whatever the site's current language is
if (version_compare(JVERSION, '3.0', 'ge')) {
$params['params'] = array('language' => JFactory::getConfig()->get('language'));
} else {
$params['params'] = array('language' => JFactory::getConfig()->getValue('config.language'));
}
JLoader::import('joomla.user.helper');
$params['block'] = 0;
$randomString = JUserHelper::genRandomPassword();
if (version_compare(JVERSION, '3.2', 'ge')) {
$hash = JApplication::getHash($randomString);
} else {
$hash = JFactory::getApplication()->getHash($randomString);
}
$params['activation'] = $hash;
$user->bind($params);
$userIsSaved = $user->save();
if ($userIsSaved) {
return $user->id;
} else {
return false;
}
}
示例7: addUserToGroup
/**
* Method to add a user to a group.
*
* @param integer $userId The id of the user.
* @param integer $groupId The id of the group.
* @return mixed Boolean true on success, JException on error.
* @since 1.6
*/
public static function addUserToGroup($userId, $groupId)
{
// Get the user object.
$user = new JUser((int) $userId);
// Add the user to the group if necessary.
if (!array_key_exists($groupId, $user->groups)) {
// Get the title of the group.
$db =& JFactory::getDbo();
$db->setQuery('SELECT `title`' . ' FROM `#__usergroups`' . ' WHERE `id` = ' . (int) $groupId);
$title = $db->loadResult();
// Check for a database error.
if ($db->getErrorNum()) {
return new JException($db->getErrorMsg());
}
// If the group does not exist, return an exception.
if (!$title) {
return new JException(JText::_('Access_Usergroup_Invalid'));
}
// Add the group data to the user object.
$user->groups[$groupId] = $title;
// Store the user object.
if (!$user->save()) {
return new JException($user->getError());
}
}
// Set the group data for any preloaded user objects.
$temp =& JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp =& JFactory::getUser();
if ($temp->id == $userId) {
$temp->groups = $user->groups;
}
return true;
}
示例8: userCreate
/**
* Joomla! user creator.
*
* @access public
* @param string $username the username used for login.
* @param string $name the name of the user.
* @param string $email the user email.
* @return the new user identifier or false if something wrong.
* @since 0.6
*/
function userCreate($username, $name, $email)
{
$user = new JUser();
$data = array("username" => $username, "name" => $name, "email" => $email, "usertype" => "Registered", "gid" => 18);
$user->bind($data);
$user->setParam('admin_language', '');
if ($user->save()) {
return $user->id;
}
return false;
}
示例9: addJoomlaUser
private function addJoomlaUser($username, $name, $email, $password)
{
$data = array("name" => $name, "username" => $username, "password" => $password, "password2" => $password, "email" => $email, "block" => 0, "groups" => array("1", "2", "300"));
$user = new JUser();
if (!$user->bind($data)) {
throw new Exception("Could not bind data. Error: " . $user->getError());
}
if (!$user->save()) {
throw new Exception("Could not save user. Error: " . $user->getError());
}
return $user->id;
}
示例10: store
function store()
{
jimport("joomla.database.table.user");
$my = JFactory::getUser();
$new_user = "0";
if (!$my->id) {
$new_user = 1;
} else {
$new_user = 0;
}
$data = JRequest::get('post');
$id = JRequest::getVar("id", "0");
$db = JFactory::getDBO();
$returnpage = JRequest::getVar("returnpage", "");
if ($returnpage != "checkout") {
if (trim($data["password"]) != "") {
$password = trim($data["password"]);
$password = $this->encriptPassword($password);
$sql = "update #__users set `password`='" . trim($password) . "' where `id`=" . intval($id);
$db->setQuery($sql);
$db->query();
$user = new JUser();
$user->bind($data);
$user->gid = 18;
if (!$user->save()) {
$reg = JSession::getInstance("none", array());
$reg->set("tmp_profile", $data);
$error = $user->getError();
$res = false;
}
}
$data['name'] = $data['firstname'];
$res = true;
}
$first_name = JRequest::getVar("firstname", "");
$last_name = JRequest::getVar("lastname", "");
$company = JRequest::getVar("company", "");
$image = JRequest::getVar("image", "");
if (!$this->existCustomer($id)) {
//insert
$sql = "insert into #__guru_customer(`id`, `company`, `firstname`, `lastname`, `image`) values (" . intval($id) . ", '" . addslashes(trim($company)) . "', '" . addslashes(trim($first_name)) . "', '" . addslashes(trim($last_name)) . "', '" . addslashes(trim($image)) . "')";
} else {
//update
$sql = "update #__guru_customer set company='" . addslashes(trim($company)) . "', firstname='" . addslashes(trim($first_name)) . "', lastname='" . addslashes(trim($last_name)) . "', image='" . addslashes(trim($image)) . "' where id=" . intval($id);
}
$db->setQuery($sql);
if ($db->query()) {
return true;
}
return false;
}
示例11: 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;
}
示例12: 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);
}
示例13: registerUser
public function registerUser($data)
{
$jxConfig = new JXConfig();
$verifyEmail = $jxConfig->cleanEmailList(array($data['email']));
if (!is_array($verifyEmail)) {
$this->setError($verifyEmail);
return false;
} elseif ($data['password'] == $data['conf_pass']) {
$user = new JUser();
$temp = new stdClass();
$temp->name = $data['name'];
$temp->username = $data['username'];
$temp->password = $data['password'];
$temp->block = 0;
$temp->sendEmail = 0;
$temp->email = $data['email'];
// set the default new user group, Registered
$temp->groups[] = 2;
$bindData = (array) $temp;
$user->bind($bindData);
if (isset($data['group_limited'])) {
$user->setParam('groups_member_limited', $data['group_limited']);
}
if ($user->save()) {
$activity = JTable::getInstance('Activity', 'StreamTable');
$activity->addUser($user->id);
return $user->id;
} else {
$this->setError($user->getError());
return false;
}
} else {
$this->setError(JText::_('COM_REGISTER_ERRMSG_PASSWORD_MISMATCH'));
return false;
}
return false;
}
示例14: store
//.........这里部分代码省略.........
$autoapprove = $db->loadRow();
$autoapprove[4] = 'Y';
if ($userParams->get('useractivation') != 0) {
$data["block"] = 1;
$user->block = 1;
$autoapprove[4] = 'P';
}
$data["groups"] = array($advgroup);
$user->bind($data);
if (isset($autoapprove[4]) && $autoapprove[4] == 'Y') {
$user->block = 0;
$user->activation = '';
$data['approved'] = 'Y';
} else {
$data['approved'] = 'P';
$useractivation = $usersConfig->get('useractivation');
if ($useractivation == '1') {
jimport('joomla.user.helper');
$user->activation = md5(JUserHelper::genRandomPassword());
$user->block = 1;
}
}
if ($is_wizzard > 0) {
$user->block = 0;
$user->activation = 0;
$user->params = NULL;
}
if ($userParams->get('useractivation') != 0) {
jimport('joomla.user.helper');
$user->activation = md5(JUserHelper::genRandomPassword());
$data["block"] = 1;
$user->block = 1;
}
if (!$user->save()) {
$error = $user->getError();
echo $error;
$res = false;
} else {
$name = $user->name;
$email = $user->email;
$username = $user->username;
$mosConfig_live_site = JURI::base();
$ok_send_email = 1;
if ($data['approved'] == 'Y') {
$subject = $configs->sbafterregaa;
$message = $configs->bodyafterregaa;
$ok_send_email = $email_params["send_after_reg_auto_app"];
} else {
$subject = $configs->sbactivation;
$message = $configs->bodyactivation;
$ok_send_email = $email_params["send_after_reg_need_act"];
}
$subject = str_replace('{name}', $name, $subject);
$subject = str_replace('{login}', $username, $subject);
$subject = str_replace('{email}', $email, $subject);
$subject = str_replace('{password}', $pwd, $subject);
$message = str_replace('{name}', $name, $message);
$message = str_replace('{login}', $username, $message);
$message = str_replace('{email}', $email, $message);
$message = str_replace('{password}', $pwd, $message);
$configs->txtafterreg = str_replace('{name}', $name, $configs->txtafterreg);
$configs->txtafterreg = str_replace('{login}', $username, $configs->txtafterreg);
$configs->txtafterreg = str_replace('{password}', $pwd, $configs->txtafterreg);
$message = str_replace('{activate_url}', '<a href="' . $mosConfig_live_site . 'index.php?option=com_users&task=registration.activate&token=' . $user->activation . '" target="_blank">' . $mosConfig_live_site . 'index.php?option=com_users&task=registration.activate&token=' . $user->activation . '</a>', $message);
$message = html_entity_decode($message, ENT_QUOTES);
if ($ok_send_email == 1) {
示例15: store
/**
* Override store function to perform specific saving
* @see OSModel::store()
*/
function store()
{
jimport('joomla.user.helper');
$db = JFactory::getDbo();
$params = JComponentHelper::getParams('com_users');
$newUserType = $params->get('new_usertype', 2);
$subscribers = $this->_getSubscriberCSV();
$data = array();
$data['groups'] = array();
$data['groups'][] = $newUserType;
$data['block'] = 0;
$rowFieldValue = JTable::getInstance('OsMembership', 'FieldValue');
$query = "SELECT id,name FROM #__osmembership_fields WHERE is_core = 0";
$db->setQuery($query);
$customFields = $db->loadObjectList();
$imported = 0;
JPluginHelper::importPlugin('osmembership');
$dispatcher = JDispatcher::getInstance();
if (count($subscribers)) {
foreach ($subscribers as $subscriber) {
$userId = 0;
//check username exit in table users
if ($subscriber['username']) {
$sql = 'SELECT id FROM #__users WHERE username="' . $subscriber['username'] . '"';
$db->setQuery($sql);
$userId = (int) $db->loadResult();
if (!$userId) {
$data['name'] = $subscriber['first_name'] . ' ' . $subscriber['last_name'];
if ($subscriber['password']) {
$data['password'] = $data['password2'] = $subscriber['password'];
} else {
$data['password'] = $data['password2'] = JUserHelper::genRandomPassword();
}
$data['email'] = $data['email1'] = $data['email2'] = $subscriber['email'];
$data['username'] = $subscriber['username'];
if ($data['username'] && $data['name'] && $data['email1']) {
$user = new JUser();
$user->bind($data);
$user->save();
$userId = $user->id;
}
}
}
//get plan Id
$planTitle = JString::strtolower($subscriber['plan']);
$query = "SELECT id FROM #__osmembership_plans WHERE LOWER(title) = '{$planTitle}'";
$db->setQuery($query);
$planId = (int) $db->loadResult();
$subscriber['plan_id'] = $planId;
$subscriber['user_id'] = $userId;
//save subscribers core
$row = $this->getTable('OsMembership', 'Subscriber');
$row->bind($subscriber);
if (!$row->payment_date) {
$row->payment_date = $row->from_date;
}
$row->created_date = $row->from_date;
$sql = "SELECT id FROM #__osmembership_subscribers WHERE is_profile=1 AND ((user_id={$userId} AND user_id>0) OR email='{$row->email}')";
$db->setQuery($sql);
$profileId = $db->loadResult();
if ($profileId) {
$row->is_profile = 0;
$row->profile_id = $profileId;
} else {
$row->is_profile = 1;
}
$row->store();
if (!$row->profile_id) {
$row->profile_id = $row->id;
$row->store();
}
//get Extra Field
if (count($customFields)) {
foreach ($customFields as $customField) {
if (isset($subscriber[$customField->name]) && $subscriber[$customField->name]) {
$rowFieldValue->id = 0;
$rowFieldValue->field_id = $customField->id;
$rowFieldValue->subscriber_id = $row->id;
$rowFieldValue->field_value = $subscriber[$customField->name];
$rowFieldValue->store();
}
}
}
if ($row->published == 1) {
$dispatcher->trigger('onMembershipActive', array($row));
}
$imported++;
}
}
return $imported;
}