本文整理汇总了PHP中user_update_user函数的典型用法代码示例。如果您正苦于以下问题:PHP user_update_user函数的具体用法?PHP user_update_user怎么用?PHP user_update_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_update_user函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_user_update_user
/**
* Test user_update_user.
*/
public function test_user_update_user()
{
global $DB;
$this->resetAfterTest();
// Create user and modify user profile.
$user = $this->getDataGenerator()->create_user();
$user->firstname = 'Test';
$user->password = 'M00dLe@T';
// Update user and capture event.
$sink = $this->redirectEvents();
user_update_user($user);
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
// Test updated value.
$dbuser = $DB->get_record('user', array('id' => $user->id));
$this->assertSame($user->firstname, $dbuser->firstname);
$this->assertNotSame('M00dLe@T', $dbuser->password);
// Test event.
$this->assertInstanceOf('\\core\\event\\user_updated', $event);
$this->assertSame($user->id, $event->objectid);
$this->assertSame('user_updated', $event->get_legacy_eventname());
$this->assertEventLegacyData($dbuser, $event);
$this->assertEquals(context_user::instance($user->id), $event->get_context());
$expectedlogdata = array(SITEID, 'user', 'update', 'view.php?id=' . $user->id, '');
$this->assertEventLegacyLogData($expectedlogdata, $event);
// Update user with no password update.
$password = $user->password = hash_internal_user_password('M00dLe@T');
user_update_user($user, false);
$dbuser = $DB->get_record('user', array('id' => $user->id));
$this->assertSame($password, $dbuser->password);
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:35,代码来源:userlib_test.php
示例2: install_site
/**
* Installs a site using $CFG->dataroot and $CFG->prefix
* @throws coding_exception
* @return void
*/
public static function install_site()
{
global $DB, $CFG;
require_once $CFG->dirroot . '/user/lib.php';
if (!defined('BEHAT_UTIL')) {
throw new coding_exception('This method can be only used by Behat CLI tool');
}
// New dataroot.
self::reset_dataroot();
$options = array();
$options['adminuser'] = 'admin';
$options['adminpass'] = 'admin';
$options['fullname'] = self::BEHATSITENAME;
$options['shortname'] = self::BEHATSITENAME;
install_cli_database($options, false);
$frontpagesummary = new admin_setting_special_frontpagedesc();
$frontpagesummary->write_setting(self::BEHATSITENAME);
// Update admin user info.
$user = $DB->get_record('user', array('username' => 'admin'));
$user->email = '[email protected]';
$user->firstname = 'Admin';
$user->lastname = 'User';
$user->city = 'Perth';
$user->country = 'AU';
user_update_user($user, false);
// Disable email message processor.
$DB->set_field('message_processors', 'enabled', '0', array('name' => 'email'));
// Sets maximum debug level.
set_config('debug', DEBUG_DEVELOPER);
set_config('debugdisplay', true);
// Keeps the current version of database and dataroot.
self::store_versions_hash();
// Stores the database contents for fast reset.
self::store_database_state();
}
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:40,代码来源:util.php
示例3: install_site
/**
* Install a site using $CFG->dataroot and $CFG->prefix
*
* @return string|bool true on success, else exception code.
*/
public static function install_site($sitefullname = "Performance test site", $siteshortname = "Performance test site", $adminpass = "admin", $adminemail = "[email protected]")
{
global $DB, $CFG;
require_once $CFG->dirroot . '/user/lib.php';
if (!defined('PERFORMANCE_SITE_GENERATOR')) {
util::performance_exception('This method can be only used by performance site generator.');
}
// If already installed, then return with error.
$tables = $DB->get_tables(false);
if (!empty($tables)) {
return self::SITE_ERROR_INSTALLED;
}
$options = array();
$options['adminuser'] = 'admin';
$options['adminpass'] = $adminpass;
$options['fullname'] = $sitefullname;
$options['shortname'] = $siteshortname;
install_cli_database($options, false);
$frontpagesummary = new \admin_setting_special_frontpagedesc();
$frontpagesummary->write_setting($sitefullname);
// Update admin user info.
$user = $DB->get_record('user', array('username' => 'admin'));
$user->email = $adminemail;
$user->firstname = 'Admin';
$user->lastname = 'User';
$user->city = 'Perth';
$user->country = 'AU';
user_update_user($user, false);
// Disable email message processor.
$DB->set_field('message_processors', 'enabled', '0', array('name' => 'email'));
// Disable some settings that are not wanted on test sites.
set_config('noemailever', 1);
// Enable web cron.
set_config('cronclionly', 0);
$CFG->dboptions = array('dbpersist' => 1);
// Keeps the current version of components hash.
self::store_versions_hash();
}
开发者ID:rajeshtaneja,项目名称:moodle-performance-toolkit,代码行数:43,代码来源:installer.php
示例4: user_update_user
if ($user = $DB->get_record('user', array('id' => $suspend, 'mnethostid' => $CFG->mnet_localhost_id, 'deleted' => 0))) {
if (!is_siteadmin($user) and $USER->id != $user->id and $user->suspended != 1) {
$user->suspended = 1;
// Force logout.
\core\session\manager::kill_user_sessions($user->id);
user_update_user($user, false);
}
}
redirect($returnurl);
} else {
if ($unsuspend and confirm_sesskey()) {
require_capability('moodle/user:update', $sitecontext);
if ($user = $DB->get_record('user', array('id' => $unsuspend, 'mnethostid' => $CFG->mnet_localhost_id, 'deleted' => 0))) {
if ($user->suspended != 0) {
$user->suspended = 0;
user_update_user($user, false);
}
}
redirect($returnurl);
} else {
if ($unlock and confirm_sesskey()) {
require_capability('moodle/user:update', $sitecontext);
if ($user = $DB->get_record('user', array('id' => $unlock, 'mnethostid' => $CFG->mnet_localhost_id, 'deleted' => 0))) {
login_unlock_account($user);
}
redirect($returnurl);
}
}
}
}
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:31,代码来源:user.php
示例5: execute
//.........这里部分代码省略.........
$consumers[] = $consumer;
$params = array('lti_message_type' => self::LTI_MESSAGE_TYPE, 'id' => $ltiuser->membershipsid, 'lti_version' => self::LTI_VERSION);
mtrace("Calling memberships url '{$ltiuser->membershipsurl}' with body '" . json_encode($params) . "'");
try {
$response = sendOAuthParamsPOST('POST', $ltiuser->membershipsurl, $ltiuser->consumerkey, $ltiuser->consumersecret, 'application/x-www-form-urlencoded', $params);
} catch (\Exception $e) {
mtrace("Skipping - No response received {$mtracecontent} from '{$ltiuser->membershipsurl}'");
mtrace($e->getMessage());
continue;
}
// Check the response from the consumer.
$data = new \SimpleXMLElement($response);
// Check if we did not receive a valid response.
if (empty($data->statusinfo)) {
mtrace("Skipping - Bad response received {$mtracecontent} from '{$ltiuser->membershipsurl}'");
mtrace('Skipping - Error parsing the XML received \'' . substr($response, 0, 125) . '\' ... (Displaying only 125 chars)');
continue;
}
// Check if we did not receive a valid response.
if (strpos(strtolower($data->statusinfo->codemajor), 'success') === false) {
mtrace('Skipping - Error received from the remote system: ' . $data->statusinfo->codemajor . ' ' . $data->statusinfo->severity . ' ' . $data->statusinfo->codeminor);
continue;
}
$members = $data->memberships->member;
mtrace(count($members) . ' members received.');
foreach ($members as $member) {
// Set the user data.
$user = new \stdClass();
$user->username = \enrol_lti\helper::create_username($ltiuser->consumerkey, $member->user_id);
$user->firstname = \core_user::clean_field($member->person_name_given, 'firstname');
$user->lastname = \core_user::clean_field($member->person_name_family, 'lastname');
$user->email = \core_user::clean_field($member->person_contact_email_primary, 'email');
// Get the user data from the LTI consumer.
$user = \enrol_lti\helper::assign_user_tool_data($tool, $user);
if (!($dbuser = $DB->get_record('user', array('username' => $user->username, 'deleted' => 0)))) {
if ($tool->membersyncmode == \enrol_lti\helper::MEMBER_SYNC_ENROL_AND_UNENROL || $tool->membersyncmode == \enrol_lti\helper::MEMBER_SYNC_ENROL_NEW) {
// If the email was stripped/not set then fill it with a default one. This
// stops the user from being redirected to edit their profile page.
if (empty($user->email)) {
$user->email = $user->username . "@example.com";
}
$user->auth = 'lti';
$user->id = user_create_user($user);
// Add the information to the necessary arrays.
$currentusers[] = $user->id;
$userphotos[$user->id] = $member->user_image;
}
} else {
// If email is empty remove it, so we don't update the user with an empty email.
if (empty($user->email)) {
unset($user->email);
}
$user->id = $dbuser->id;
user_update_user($user);
// Add the information to the necessary arrays.
$currentusers[] = $user->id;
$userphotos[$user->id] = $member->user_image;
}
if ($tool->membersyncmode == \enrol_lti\helper::MEMBER_SYNC_ENROL_AND_UNENROL || $tool->membersyncmode == \enrol_lti\helper::MEMBER_SYNC_ENROL_NEW) {
// Enrol the user in the course.
\enrol_lti\helper::enrol_user($tool, $user->id);
}
}
}
// Now we check if we have to unenrol users who were not listed.
if ($tool->membersyncmode == \enrol_lti\helper::MEMBER_SYNC_ENROL_AND_UNENROL || $tool->membersyncmode == \enrol_lti\helper::MEMBER_SYNC_UNENROL_MISSING) {
// Go through the users and check if any were never listed, if so, remove them.
foreach ($ltiusers as $ltiuser) {
if (!in_array($ltiuser->userid, $currentusers)) {
$instance = new \stdClass();
$instance->id = $tool->enrolid;
$instance->courseid = $tool->courseid;
$instance->enrol = 'lti';
$ltiplugin->unenrol_user($instance, $ltiuser->id);
}
}
}
}
mtrace("Completed - Synced members for tool '{$tool->id}' in the course '{$tool->courseid}'. " . "Processed {$usercount} users; enrolled {$enrolcount} members; unenrolled {$unenrolcount} members.");
mtrace("");
}
// Sync the user profile photos.
mtrace("Started - Syncing user profile images.");
$counter = 0;
if (!empty($userphotos)) {
foreach ($userphotos as $userid => $url) {
if ($url) {
$result = \enrol_lti\helper::update_user_profile_image($userid, $url);
if ($result === \enrol_lti\helper::PROFILE_IMAGE_UPDATE_SUCCESSFUL) {
$counter++;
mtrace("Profile image succesfully downloaded and created for user '{$userid}' from {$url}.");
} else {
mtrace($result);
}
}
}
}
mtrace("Completed - Synced {$counter} profile images.");
}
}
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:sync_members.php
示例6: install_site
/**
* Installs a site using $CFG->dataroot and $CFG->prefix
* @throws coding_exception
* @return void
*/
public static function install_site()
{
global $DB, $CFG;
require_once $CFG->dirroot . '/user/lib.php';
if (!defined('BEHAT_UTIL')) {
throw new coding_exception('This method can be only used by Behat CLI tool');
}
$tables = $DB->get_tables(false);
if (!empty($tables)) {
behat_error(BEHAT_EXITCODE_INSTALLED);
}
// New dataroot.
self::reset_dataroot();
$options = array();
$options['adminuser'] = 'admin';
$options['adminpass'] = 'admin';
$options['fullname'] = self::BEHATSITENAME;
$options['shortname'] = self::BEHATSITENAME;
install_cli_database($options, false);
// We need to keep the installed dataroot filedir files.
// So each time we reset the dataroot before running a test, the default files are still installed.
self::save_original_data_files();
$frontpagesummary = new admin_setting_special_frontpagedesc();
$frontpagesummary->write_setting(self::BEHATSITENAME);
// Update admin user info.
$user = $DB->get_record('user', array('username' => 'admin'));
$user->email = '[email protected]';
$user->firstname = 'Admin';
$user->lastname = 'User';
$user->city = 'Perth';
$user->country = 'AU';
user_update_user($user, false);
// Disable email message processor.
$DB->set_field('message_processors', 'enabled', '0', array('name' => 'email'));
// Sets maximum debug level.
set_config('debug', DEBUG_DEVELOPER);
set_config('debugdisplay', 1);
// Disable some settings that are not wanted on test sites.
set_config('noemailever', 1);
// Enable web cron.
set_config('cronclionly', 0);
// Keeps the current version of database and dataroot.
self::store_versions_hash();
// Stores the database contents for fast reset.
self::store_database_state();
}
开发者ID:janeklb,项目名称:moodle,代码行数:51,代码来源:util.php
示例7: hash_internal_user_password
// Use a low cost factor when generating bcrypt hash otherwise
// hashing would be slow when uploading lots of users. Hashes
// will be automatically updated to a higher cost factor the first
// time the user logs in.
$existinguser->password = hash_internal_user_password($user->password, true);
$upt->track('password', $user->password, 'normal', false);
} else {
// do not print password when not changed
$upt->track('password', '', 'normal', false);
}
}
}
}
if ($doupdate or $existinguser->password !== $oldpw) {
// We want only users that were really updated.
user_update_user($existinguser, false, false);
$upt->track('status', $struserupdated);
$usersupdated++;
if (!$remoteuser) {
// pre-process custom profile menu fields data from csv file
$existinguser = uu_pre_process_custom_profile_data($existinguser);
// save custom profile fields data from csv file
profile_save_data($existinguser);
}
if ($bulk == UU_BULK_UPDATED or $bulk == UU_BULK_ALL) {
if (!in_array($user->id, $SESSION->bulk_users)) {
$SESSION->bulk_users[] = $user->id;
}
}
// Trigger event.
\core\event\user_updated::create_from_userid($existinguser->id)->trigger();
开发者ID:educakanchay,项目名称:campus,代码行数:31,代码来源:index.php
示例8: update_users
/**
* Update users
*
* @param array $users
* @return null
* @since Moodle 2.2
*/
public static function update_users($users)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/user/lib.php";
require_once $CFG->dirroot . "/user/profile/lib.php";
//required for customfields related function
// Ensure the current user is allowed to run this function
$context = context_system::instance();
require_capability('moodle/user:update', $context);
self::validate_context($context);
$params = self::validate_parameters(self::update_users_parameters(), array('users' => $users));
$transaction = $DB->start_delegated_transaction();
foreach ($params['users'] as $user) {
if (empty($user['country'])) {
//Allowing empty country leads to login issues. Let's not allow such updates
continue;
}
user_update_user($user);
//update user custom fields
if (!empty($user['customfields'])) {
foreach ($user['customfields'] as $customfield) {
$user["profile_field_" . $customfield['type']] = $customfield['value'];
//profile_save_data() saves profile file
//it's expecting a user with the correct id,
//and custom field to be named profile_field_"shortname"
}
profile_save_data((object) $user);
events_trigger('user_updated', (object) $user);
}
//preferences
if (!empty($user['preferences'])) {
foreach ($user['preferences'] as $preference) {
set_user_preference($preference['type'], $preference['value'], $user['id']);
}
}
}
$transaction->allow_commit();
return null;
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:46,代码来源:externallib.php
示例9: user_create_user
$user->email = $user->username . "@example.com";
}
$user->auth = 'lti';
$user->id = user_create_user($user);
// Get the updated user record.
$user = $DB->get_record('user', array('id' => $user->id));
} else {
if (\enrol_lti\helper::user_match($user, $dbuser)) {
$user = $dbuser;
} else {
// If email is empty remove it, so we don't update the user with an empty email.
if (empty($user->email)) {
unset($user->email);
}
$user->id = $dbuser->id;
user_update_user($user);
// Get the updated user record.
$user = $DB->get_record('user', array('id' => $user->id));
}
}
// Update user image.
$image = false;
if (!empty($ltirequest->info['user_image'])) {
$image = $ltirequest->info['user_image'];
} else {
if (!empty($ltirequest->info['custom_user_image'])) {
$image = $ltirequest->info['custom_user_image'];
}
}
// Check if there is an image to process.
if ($image) {
开发者ID:sirromas,项目名称:lms,代码行数:31,代码来源:tool.php
示例10: stdClass
* 1. Update user profile.
* 2. Save request data into request table.
* 3. Take the user to the list of request and pass the message if the request was made
* successfully.
*/
$profile = new stdClass();
$profile->id = $USER->id;
$profile->firstname = $fromform->firstname;
$profile->lastname = $fromform->lastname;
$profile->email = $fromform->email;
$profile->country = $fromform->country;
$profile->city = $fromform->city;
$profile->address = $fromform->address;
$profile->phone1 = $fromform->phone1;
// Update user.
user_update_user($profile, false, true);
// Reload from db.
$user = $DB->get_record('user', array('id' => $profile->id), '*', MUST_EXIST);
// Override old $USER session variable if needed.
if ($USER->id == $user->id) {
// Override old $USER session variable if needed.
foreach ((array) $user as $variable => $value) {
if ($variable === 'description' or $variable === 'password') {
// These are not set for security nad perf reasons.
continue;
}
$USER->{$variable} = $value;
}
}
$today = time();
$request = new stdClass();
开发者ID:andrewmrg,项目名称:ps_selfstudy,代码行数:31,代码来源:requestcourse.php
示例11: update_users
/**
* Update users
*
* @param array $users
* @return null
* @since Moodle 2.2
*/
public static function update_users($users)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/user/lib.php";
require_once $CFG->dirroot . "/user/profile/lib.php";
// Required for customfields related function.
// Ensure the current user is allowed to run this function.
$context = context_system::instance();
require_capability('moodle/user:update', $context);
self::validate_context($context);
$params = self::validate_parameters(self::update_users_parameters(), array('users' => $users));
$filemanageroptions = array('maxbytes' => $CFG->maxbytes, 'subdirs' => 0, 'maxfiles' => 1, 'accepted_types' => 'web_image');
$transaction = $DB->start_delegated_transaction();
foreach ($params['users'] as $user) {
user_update_user($user, true, false);
// Update user picture if it was specified for this user.
if (empty($CFG->disableuserimages) && isset($user['userpicture'])) {
$userobject = (object) $user;
$userobject->deletepicture = null;
if ($user['userpicture'] == 0) {
$userobject->deletepicture = true;
} else {
$userobject->imagefile = $user['userpicture'];
}
core_user::update_picture($userobject, $filemanageroptions);
}
// Update user custom fields.
if (!empty($user['customfields'])) {
foreach ($user['customfields'] as $customfield) {
// Profile_save_data() saves profile file it's expecting a user with the correct id,
// and custom field to be named profile_field_"shortname".
$user["profile_field_" . $customfield['type']] = $customfield['value'];
}
profile_save_data((object) $user);
}
// Trigger event.
\core\event\user_updated::create_from_userid($user['id'])->trigger();
// Preferences.
if (!empty($user['preferences'])) {
foreach ($user['preferences'] as $preference) {
set_user_preference($preference['type'], $preference['value'], $user['id']);
}
}
}
$transaction->allow_commit();
return null;
}
开发者ID:janeklb,项目名称:moodle,代码行数:54,代码来源:externallib.php
示例12: create_users
/**
* Create one or more users
*
* @param array $users An array of users to create.
* @return array An array of arrays
*/
function create_users($users)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/user/lib.php";
require_once $CFG->dirroot . "/user/profile/lib.php";
//required for customfields related function
//TODO: move the functions somewhere else as
//they are "user" related
$availableauths = get_plugin_list('auth');
$availablethemes = get_plugin_list('theme');
$availablelangs = get_string_manager()->get_list_of_translations();
$transaction = $DB->start_delegated_transaction();
$userids = array();
foreach ($users as $user) {
// Make sure that the username doesn't already exist
if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
// $userids[] = array('id' => $user['id'], 'username' => $user['username'], 'error'=>'Username already exists: ' . $user['username']);
$user_rec = $DB->get_record('user', array('username' => $user['username']));
$user['id'] = $user_rec->id;
unset($user['password']);
unset($user['auth']);
user_update_user($user);
$userids[] = array('id' => $user['id'], 'username' => $user['username'], 'error' => 'Updated');
continue;
}
// Make sure auth is valid
if (empty($availableauths[$user['auth']])) {
$userids[] = array('id' => $user['id'], 'username' => $user['username'], 'error' => 'Invalid authentication type: ' . $user['auth']);
continue;
}
// Make sure lang is valid
if (empty($availablelangs[$user['lang']])) {
$userids[] = array('id' => $user['id'], 'username' => $user['username'], 'error' => 'Invalid language code: ' . $user['lang']);
continue;
}
// Make sure lang is valid
if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) {
//theme is VALUE_OPTIONAL,
// so no default value.
// We need to test if the client sent it
// => !empty($user['theme'])
$userids[] = array('id' => $user['id'], 'username' => $user['username'], 'error' => 'Invalid theme: ' . $user['theme']);
continue;
}
// make sure there is no data loss during truncation
$truncated = truncate_userinfo($user);
foreach ($truncated as $key => $value) {
if ($truncated[$key] !== $user[$key]) {
$userids[] = array('id' => $user['id'], 'username' => $user['username'], 'error' => 'Property: ' . $key . ' is too long: ' . $user[$key]);
continue;
}
}
$user['confirmed'] = true;
$user['mnethostid'] = $CFG->mnet_localhost_id;
$user['id'] = user_create_user($user);
// // custom fields
// if (!empty($user['customfields'])) {
// foreach ($user['customfields'] as $customfield) {
// $user["profile_field_" . $customfield['type']] = $customfield['value']; //profile_save_data() saves profile file
// //it's expecting a user with the correct id,
// //and custom field to be named profile_field_"shortname"
// }
// profile_save_data((object)$user);
// }
//
// //preferences
// if (!empty($user['preferences'])) {
// foreach ($user['preferences'] as $preference) {
// set_user_preference($preference['type'], $preference['value'], $user['id']);
// }
// }
$userids[] = array('id' => $user['id'], 'username' => $user['username'], 'error' => "");
}
$transaction->allow_commit();
return $userids;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:82,代码来源:user_creation.php
示例13: disconnect
/**
* Handle OIDC disconnection from Moodle account.
*
* @param bool $justremovetokens If true, just remove the stored OIDC tokens for the user, otherwise revert login methods.
*/
public function disconnect($justremovetokens = false, \moodle_url $redirect = null)
{
if ($redirect === null) {
$redirect = new \moodle_url('/auth/oidc/ucp.php');
}
if ($justremovetokens === true) {
global $USER, $DB, $CFG;
// Delete token data.
$DB->delete_records('auth_oidc_token', ['username' => $USER->username]);
$eventdata = ['objectid' => $USER->id, 'userid' => $USER->id];
$event = \auth_oidc\event\user_disconnected::create($eventdata);
$event->trigger();
redirect($redirect);
} else {
global $OUTPUT, $PAGE, $USER, $DB, $CFG;
require_once $CFG->dirroot . '/user/lib.php';
$PAGE->set_url('/auth/oidc/ucp.php');
$PAGE->set_context(\context_system::instance());
$PAGE->set_pagelayout('standard');
$USER->editing = false;
$ucptitle = get_string('ucp_disconnect_title', 'auth_oidc', $this->config->opname);
$PAGE->navbar->add($ucptitle, $PAGE->url);
$PAGE->set_title($ucptitle);
// Check if we have recorded the user's previous login method.
$prevmethodrec = $DB->get_record('auth_oidc_prevlogin', ['userid' => $USER->id]);
$prevauthmethod = !empty($prevmethodrec) && is_enabled_auth($prevmethodrec->method) === true ? $prevmethodrec->method : null;
// Manual is always available, we don't need it twice.
if ($prevauthmethod === 'manual') {
$prevauthmethod = null;
}
// We need either the user's previous method or the manual login plugin to be enabled for disconnection.
if (empty($prevauthmethod) && is_enabled_auth('manual') !== true) {
throw new \moodle_exception('errornodisconnectionauthmethod', 'auth_oidc');
}
// Check to see if the user has a username created by OIDC, or a self-created username.
// OIDC-created usernames are usually very verbose, so we'll allow them to choose a sensible one.
// Otherwise, keep their existing username.
$oidctoken = $DB->get_record('auth_oidc_token', ['username' => $USER->username]);
$ccun = isset($oidctoken->oidcuniqid) && strtolower($oidctoken->oidcuniqid) === $USER->username ? true : false;
$customdata = ['canchooseusername' => $ccun, 'prevmethod' => $prevauthmethod];
$mform = new \auth_oidc\form\disconnect('?action=disconnectlogin', $customdata);
if ($mform->is_cancelled()) {
redirect($redirect);
} else {
if ($fromform = $mform->get_data()) {
$origusername = $USER->username;
if (empty($fromform->newmethod) || $fromform->newmethod !== $prevauthmethod && $fromform->newmethod !== 'manual') {
throw new \moodle_exception('errorauthdisconnectinvalidmethod', 'auth_oidc');
}
$updateduser = new \stdClass();
if ($fromform->newmethod === 'manual') {
if (empty($fromform->password)) {
throw new \moodle_exception('errorauthdisconnectemptypassword', 'auth_oidc');
}
if ($customdata['canchooseusername'] === true) {
if (empty($fromform->username)) {
throw new \moodle_exception('errorauthdisconnectemptyusername', 'auth_oidc');
}
if (strtolower($fromform->username) !== $USER->username) {
$newusername = strtolower($fromform->username);
$usercheck = ['username' => $newusername, 'mnethostid' => $CFG->mnet_localhost_id];
if ($DB->record_exists('user', $usercheck) === false) {
$updateduser->username = $newusername;
} else {
throw new \moodle_exception('errorauthdisconnectusernameexists', 'auth_oidc');
}
}
}
$updateduser->auth = 'manual';
$updateduser->password = $fromform->password;
} else {
if ($fromform->newmethod === $prevauthmethod) {
$updateduser->auth = $prevauthmethod;
// We can't use user_update_user as it will rehash the value.
if (!empty($prevmethodrec->password)) {
$manualuserupdate = new \stdClass();
$manualuserupdate->id = $USER->id;
$manualuserupdate->password = $prevmethodrec->password;
$DB->update_record('user', $manualuserupdate);
}
}
}
// Update user.
$updateduser->id = $USER->id;
user_update_user($updateduser);
// Delete token data.
$DB->delete_records('auth_oidc_token', ['username' => $origusername]);
$eventdata = ['objectid' => $USER->id, 'userid' => $USER->id];
$event = \auth_oidc\event\user_disconnected::create($eventdata);
$event->trigger();
$USER = $DB->get_record('user', ['id' => $USER->id]);
redirect($redirect);
}
}
echo $OUTPUT->header();
//.........这里部分代码省略.........
开发者ID:jamesmcq,项目名称:o365-moodle,代码行数:101,代码来源:base.php
示例14: user_update_details
/**
* Update details for the current user
* Password is passed in plaintext.
*
* @param object $user current user object
* @param boolean $notify print notice with link and terminate
*/
public function user_update_details($user)
{
global $CFG, $DB, $USER;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
if ($user->password == $user->confirmpassword and !empty($user->password)) {
$plainpassword = $user->password;
echo $plainpassword;
$user->password = hash_internal_user_password($user->password);
$this->user_update_password($user, $user->password);
user_add_password_history($user->id, $plainpassword);
}
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
try {
$transaction = $DB->start_delegated_transaction();
user_update_user($user, false, false);
$user->profile_field_yearlevel = empty($user->profile_field_yearlevel) ? 'N/A' : $user->profile_field_yearlevel;
$user->profile_field_yearofbirth = empty($user->profile_field_yearofbirth) ? 'N/A' : $user->profile_field_yearofbirth;
$user->profile_field_whereareyoufrom = empty($user->profile_field_whereareyoufrom) ? 'Perth' : $user->profile_field_whereareyoufrom;
$USER->profile['yearlevel'] = $user->profile_field_yearlevel;
$USER->profile['yearofbirth'] = $user->profile_field_yearofbirth;
$USER->profile['whereareyoufrom'] = $user->profile_field_whereareyoufrom;
profile_save_data($user);
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
// Assuming the both inserts work, we get to the following line.
$transaction->allow_commit();
} catch (Exception $e) {
$transaction->rollback($e);
return false;
}
return $this->update_user_session($user);
}
开发者ID:posttechguy,项目名称:moodle-meditrax-local_meditraxcohort,代码行数:42,代码来源:auth.php
示例15: onLaunch
/**
* Override onLaunch with tool logic.
* @return void
*/
protected function onLaunch()
{
global $DB, $SESSION, $CFG;
// Check for valid consumer.
if (empty($this->consumer) || $this->dataConnector->loadToolConsumer($this->consumer) === false) {
$this->ok = false;
$this->message = get_string('invalidtoolconsumer', 'enrol_lti');
return;
}
$url = helper::get_launch_url($this->tool->id);
// If a tool proxy has been stored for the current consumer trying to access a tool,
// check that the tool is being launched from the correct url.
$correctlaunchurl = false;
if (!empty($this->consumer->toolProxy)) {
$proxy = json_decode($this->consumer->toolProxy);
$handlers = $proxy->tool_profile->resource_handler;
foreach ($handlers as $handler) {
foreach ($handler->message as $message) {
$handlerurl = new moodle_url($message->path);
$fullpath = $handlerurl->out(false);
if ($message->message_type == "basic-lti-launch-request" && $fullpath == $url) {
$correctlaunchurl = true;
break 2;
}
}
}
} else {
if ($this->tool->secret == $this->consumer->secret) {
// Test if the LTI1 secret for this tool is being used. Then we know the correct tool is being launched.
$correctlaunchurl = true;
}
}
if (!$correctlaunchurl) {
$this->ok = false;
$this->message = get_string('invalidrequest', 'enrol_lti');
return;
}
// Before we do anything check that the context is valid.
$tool = $this->tool;
$context = context::instance_by_id($tool->contextid);
// Set the user data.
$user = new stdClass();
$user->username = helper::create_username($this->consumer->getKey(), $this->user->ltiUserId);
if (!empty($this->user->firstname)) {
$user->firstname = $this->user->firstname;
} else {
$user->firstname = $this->user->getRecordId();
}
if (!empty($this->user->lastname)) {
$user->lastname = $this->user->lastname;
} else {
$user->lastname = $this->tool->contextid;
}
$user->email = core_user::clean_field($this->user->email, 'email');
// Get the user data from the LTI consumer.
$user = helper::assign_user_tool_data($tool, $user);
// Check if the user exists.
if (!($dbuser = $DB->get_record('user', ['username' => $user->username, 'deleted' => 0]))) {
// If the email was stripped/not set then fill it with a default one. This
// stops the user from being redirected to edit their profile page.
if (empty($user->email)) {
$user->email = $user->username . "@example.com";
}
$user->auth = 'lti';
$user->id = \user_create_user($user);
// Get the updated user record.
$user = $DB->get_record('user', ['id' => $user->id]);
} else {
if (helper::user_match($user, $dbuser)) {
$user = $dbuser;
} else {
// If email is empty remove it, so we don't update the user with an empty email.
if (empty($user->email)) {
unset($user->email);
}
$user->id = $dbuser->id;
\user_update_user($user);
// Get the updated user record.
$user = $DB->get_record('user', ['id' => $user->id]);
}
}
// Update user image.
if (isset($this->user) && isset($this->user->image) && !empty($this->user->image)) {
$image = $this->user->image;
} else {
// Use custom_user_image parameter as a fallback.
$image = $this->resourceLink->getSetting('custom_user_image');
}
// Check if there is an image to process.
if ($image) {
helper::update_user_profile_image($user->id, $image);
}
// Check if we need to force the page layout to embedded.
$isforceembed = $this->resourceLink->getSetting('custom_force_embed') == 1;
// Check if we are an instructor.
$isinstructor = $this->user->isStaff() || $this->user->isAdmin();
//.........这里部分代码省略.........
开发者ID:lucaboesch,项目名称:moodle,代码行数:101,代码来源:tool_provider.php
示例16: update_users
public static function update_users($users) {
global $CFG, $DB;
require_once($CFG->dirroot."/user/lib.php");
require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function
//TODO: move the functions somewhere else as
//they are "user" related
// Ensure the current user is allowed to run this function
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/user:update', $context);
self::validate_context($context);
$params = self::validate_parameters(self::update_users_parameters(), array('users'=>$users));
$transaction = $DB->start_delegated_transaction();
foreach ($params['users'] as $user) {
user_update_user($user);
//update user custom fields
if(!empty($user['customfields'])) {
foreach($user['customfields'] as $customfield) {
$user["profile_field_".$customfield['type']] = $customfield['value']; //profile_save_data() saves profile file
//it's expecting a user with the correct id,
//and custom field to be named
|
请发表评论