本文整理汇总了PHP中core\event\user_created类的典型用法代码示例。如果您正苦于以下问题:PHP user_created类的具体用法?PHP user_created怎么用?PHP user_created使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了user_created类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: handle_user_created
/**
* Handle a user being created .
*
* Does the following:
* - Check if user is using OpenID Connect auth plugin.
* - If so, gets additional information from Azure AD and updates the user.
*
* @param \core\event\user_created $event The triggered event.
* @return bool Success/Failure.
*/
public static function handle_user_created(\core\event\user_created $event)
{
global $DB;
$eventdata = $event->get_data();
if (empty($eventdata['objectid'])) {
return false;
}
$createduserid = $eventdata['objectid'];
$user = $DB->get_record('user', ['id' => $createduserid]);
if (!empty($user) && isset($user->auth) && $user->auth === 'oidc') {
static::get_additional_user_info($createduserid);
}
return true;
}
开发者ID:jamesmcq,项目名称:o365-moodle,代码行数:24,代码来源:observers.php
示例2: user_create_user
/**
* Creates a user
*
* @throws moodle_exception
* @param stdClass $user user to create
* @param bool $updatepassword if true, authentication plugin will update password.
* @param bool $triggerevent set false if user_created event should not be triggred.
* This will not affect user_password_updated event triggering.
* @return int id of the newly created user
*/
function user_create_user($user, $updatepassword = true, $triggerevent = true)
{
global $CFG, $DB;
// Set the timecreate field to the current time.
if (!is_object($user)) {
$user = (object) $user;
}
/* GWL : For Phone Field Remove Check */
/*
// Check username.
if ($user->username !== core_text::strtolower($user->username)) {
throw new moodle_exception('usernamelowercase');
} else {
if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
throw new moodle_exception('invalidusername');
}
}
*/
/* GWL : For Phone Field Remove Check */
// Save the password in a temp value for later.
if ($updatepassword && isset($user->password)) {
// Check password toward the password policy.
if (!check_password_policy($user->password, $errmsg)) {
throw new moodle_exception($errmsg);
}
$userpassword = $user->password;
unset($user->password);
}
// Make sure calendartype, if set, is valid.
if (!empty($user->calendartype)) {
$availablecalendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
if (empty($availablecalendartypes[$user->calendartype])) {
$user->calendartype = $CFG->calendartype;
}
} else {
$user->calendartype = $CFG->calendartype;
}
$user->timecreated = time();
$user->timemodified = $user->timecreated;
// Insert the user into the database.
$newuserid = $DB->insert_record('user', $user);
// Create USER context for this user.
$usercontext = context_user::instance($newuserid);
// Update user password if necessary.
if (isset($userpassword)) {
// Get full database user row, in case auth is default.
$newuser = $DB->get_record('user', array('id' => $newuserid));
$authplugin = get_auth_plugin($newuser->auth);
$authplugin->user_update_password($newuser, $userpassword);
}
// Trigger event If required.
if ($triggerevent) {
\core\event\user_created::create_from_userid($newuserid)->trigger();
}
return $newuserid;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:66,代码来源:lib.php
示例3: user_create_user
/**
* Creates a user
*
* @param stdClass $user user to create
* @param bool $updatepassword if true, authentication plugin will update password.
* @return int id of the newly created user
*/
function user_create_user($user, $updatepassword = true)
{
global $DB;
// Set the timecreate field to the current time.
if (!is_object($user)) {
$user = (object) $user;
}
// Check username.
if ($user->username !== core_text::strtolower($user->username)) {
throw new moodle_exception('usernamelowercase');
} else {
if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
throw new moodle_exception('invalidusername');
}
}
// Save the password in a temp value for later.
if ($updatepassword && isset($user->password)) {
// Check password toward the password policy.
if (!check_password_policy($user->password, $errmsg)) {
throw new moodle_exception($errmsg);
}
$userpassword = $user->password;
unset($user->password);
}
$user->timecreated = time();
$user->timemodified = $user->timecreated;
// Insert the user into the database.
$newuserid = $DB->insert_record('user', $user);
// Create USER context for this user.
$usercontext = context_user::instance($newuserid);
// Update user password if necessary.
if (isset($userpassword)) {
// Get full database user row, in case auth is default.
$newuser = $DB->get_record('user', array('id' => $newuserid));
$authplugin = get_auth_plugin($newuser->auth);
$authplugin->user_update_password($newuser, $userpassword);
}
// Trigger event.
$event = \core\event\user_created::create(array('objectid' => $newuserid, 'context' => $usercontext));
$event->trigger();
return $newuserid;
}
开发者ID:helenagarcia90,项目名称:moodle,代码行数:49,代码来源:lib.php
示例4: application_user_signup
function application_user_signup($user)
{
// Derived from email->user_signup
global $CFG, $PAGE, $OUTPUT;
$user->password = hash_internal_user_password($user->password);
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$user->id = user_create_user($user, false, false);
// Save any custom profile field information
profile_save_data($user);
// Save contact information
write_contact_details($user->id, $user);
// Trigger event
\core\event\user_created::create_from_userid($user->id)->trigger();
if (!send_application_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth_email');
}
$PAGE->set_title($CFG->pageheading . ': ' . get_string('emailconfirm'));
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), $CFG->wwwroot . '/local/obu_application/login.php');
}
开发者ID:OBU-OBIS,项目名称:moodle-local_obu_application,代码行数:22,代码来源:locallib.php
示例5: create_hub_token
/**
* Create a user, role and token. Return the created token id.
* @param string $rolename the role to create/use - will be assign to the user
* @param string $servicename service to link to the new token
* @param string $username user to link to the new token
* @param array $capabilities list of capabilities to add to the role
* @return object created token
*/
function create_hub_token($rolename, $servicename, $username, $capabilities)
{
global $CFG, $DB;
//requires libraries
require_once $CFG->dirroot . '/user/lib.php';
//check the hidden service
//because we cannot know the id of the service, we consider that hidden services have unique name!
$services = $DB->get_records('external_services', array('name' => $servicename));
//if ever we have two hidden service with the same name, it's due to a programmation error
if (count($services) > 1) {
throw new moodle_exception('hiddenservicewithsamename');
}
if (count($services) < 1) {
throw new moodle_exception('unknownservicename');
}
$role = $DB->get_record('role', array('name' => $rolename));
if (empty($role)) {
$roleid = create_role($rolename, clean_param($rolename, PARAM_ALPHAEXT), get_string('hubwsroledescription', 'local_hub'), '', true);
} else {
$roleid = $role->id;
}
//check and create a user
$user = $DB->get_record('user', array('username' => $username, 'idnumber' => $username));
if (empty($user)) {
$user = new stdClass();
$user->username = $username;
$user->firstname = $username;
$user->lastname = get_string('donotdeleteormodify', 'local_hub');
$user->password = '';
//login no authorised with webservice authentication
$user->auth = 'webservice';
$user->confirmed = 1;
//need to be confirmed otherwise got deleted
$user->idnumber = $username;
$user->mnethostid = 1;
$user->description = get_string('hubwsuserdescription', 'local_hub');
$user->timecreated = time();
$user->timemodified = $user->timecreated;
// Add extra fields to prevent a debug notice.
$userfields = get_all_user_name_fields();
foreach ($userfields as $key => $field) {
if (!isset($user->{$key})) {
$user->{$key} = null;
}
}
// Insert the "site" user into the database.
$user->id = $DB->insert_record('user', $user);
\core\event\user_created::create_from_userid($user->id)->trigger();
add_to_log(SITEID, 'user', get_string('create'), '/view.php?id=' . $user->id, fullname($user));
}
//check and assign the role to user
$context = context_system::instance();
$existingroleassign = $DB->get_records('role_assignments', array('roleid' => $roleid, 'contextid' => $context->id, 'userid' => $user->id), 'id');
if (empty($existingroleassign)) {
role_assign($roleid, $user->id, $context->id);
}
//check and assign capabilities to role
$capabilities[] = 'webservice/xmlrpc:use';
if (empty($role)) {
$role = new stdClass();
$role->id = $roleid;
}
$rolecapabilities = get_capabilities_from_role_on_context($role, $context);
if (!empty($capabilities)) {
foreach ($capabilities as $capability) {
$capabilityassigned = false;
foreach ($rolecapabilities as $rolecapability) {
if ($rolecapability->capability == $capability) {
$capabilityassigned = true;
break;
}
}
if (!$capabilityassigned) {
assign_capability($capability, CAP_ALLOW, $roleid, $context->id);
}
}
}
//enable the hidden service and assign it to the user
foreach ($services as $service) {
//there should be only one service into the array!!!
//checked at beginning of the function
$serviceid = $service->id;
//if no hidden token was created for this service, we need to enable it
if (!$service->enabled) {
$service->enabled = 1;
$DB->update_record('external_services', $service);
}
$serviceuser = $DB->get_record('external_services_users', array('externalserviceid' => $serviceid, 'userid' => $user->id));
if (empty($serviceuser)) {
$serviceuser = new stdClass();
$serviceuser->externalserviceid = $serviceid;
$serviceuser->userid = $user->id;
//.........这里部分代码省略.........
开发者ID:k-holland,项目名称:moodle-local_hub,代码行数:101,代码来源:lib.php
示例6: test_events_traversable
/**
* Test sql_reader::get_events_select_iterator.
* @return void
*/
public function test_events_traversable()
{
global $DB;
$this->resetAfterTest();
$this->preventResetByRollback();
$this->setAdminUser();
set_config('enabled_stores', 'logstore_standard', 'tool_log');
$manager = get_log_manager(true);
$stores = $manager->get_readers();
$store = $stores['logstore_standard'];
$events = $store->get_events_select_iterator('', array(), '', 0, 0);
$this->assertFalse($events->valid());
// Here it should be already closed, but we should be allowed to
// over-close it without exception.
$events->close();
$user = $this->getDataGenerator()->create_user();
for ($i = 0; $i < 1000; $i++) {
\core\event\user_created::create_from_userid($user->id)->trigger();
}
$store->flush();
// Check some various sizes get the right number of elements.
$this->assertEquals(1, iterator_count($store->get_events_select_iterator('', array(), '', 0, 1)));
$this->assertEquals(2, iterator_count($store->get_events_select_iterator('', array(), '', 0, 2)));
$iterator = $store->get_events_select_iterator('', array(), '', 0, 500);
$this->assertInstanceOf('\\core\\event\\base', $iterator->current());
$this->assertEquals(500, iterator_count($iterator));
$iterator->close();
// Look for non-linear memory usage for the iterator version.
$mem = memory_get_usage();
$events = $store->get_events_select('', array(), '', 0, 0);
$arraymemusage = memory_get_usage() - $mem;
$mem = memory_get_usage();
$eventsit = $store->get_events_select_iterator('', array(), '', 0, 0);
$eventsit->close();
$itmemusage = memory_get_usage() - $mem;
$this->assertInstanceOf('\\Traversable', $eventsit);
$this->assertLessThan($arraymemusage / 10, $itmemusage);
set_config('enabled_stores', '', 'tool_log');
get_log_manager(true);
}
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:44,代码来源:store_test.php
示例7: useredit_update_bounces
// Update mail bounces.
useredit_update_bounces($user, $usernew);
// Update forum track preference.
useredit_update_trackforums($user, $usernew);
// Save custom profile fields data.
profile_save_data($usernew);
// Reload from db.
$usernew = $DB->get_record('user', array('id' => $usernew->id));
if ($createpassword) {
setnew_password_and_mail($usernew);
unset_user_preference('create_password', $usernew);
set_user_preference('auth_forcepasswordchange', 1, $usernew);
}
// Trigger update/create event, after all fields are stored.
if ($usercreated) {
\core\event\user_created::create_from_userid($usernew->id)->trigger();
} else {
\core\event\user_updated::create_from_userid($usernew->id)->trigger();
}
if ($user->id == $USER->id) {
// Override old $USER session variable.
foreach ((array) $usernew as $variable => $value) {
if ($variable === 'description' or $variable === 'password') {
// These are not set for security nad perf reasons.
continue;
}
$USER->{$variable} = $value;
}
// Preload custom fields.
profile_load_custom_fields($USER);
if (!empty($USER->newadminuser)) {
开发者ID:alanaipe2015,项目名称:moodle,代码行数:31,代码来源:editadvanced.php
示例8: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
* @return boolean success
*/
function user_signup($user, $notify = true)
{
global $CFG, $DB, $PAGE, $OUTPUT;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
if ($this->user_exists($user->username)) {
print_error('auth_ldap_user_exists', 'auth_ldap');
}
$plainslashedpassword = $user->password;
unset($user->password);
if (!$this->user_create($user, $plainslashedpassword)) {
print_error('auth_ldap_create_error', 'auth_ldap');
}
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainslashedpassword);
// Save any custom profile field information
profile_save_data($user);
$this->update_user_record($user->username);
// This will also update the stored hash to the latest algorithm
// if the existing hash is using an out-of-date algorithm (or the
// legacy md5 algorithm).
update_internal_user_password($user, $plainslashedpassword);
$user = $DB->get_record('user', array('id' => $user->id));
\core\event\user_created::create_from_userid($user->id)->trigger();
if (!send_confirmation_email($user)) {
print_error('noemail', 'auth_ldap');
}
if ($notify) {
$emailconfirm = get_string('emailconfirm');
$PAGE->set_url('/auth/ldap/auth.php');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($emailconfirm);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:47,代码来源:auth.php
示例9: create_users
/**
* Create one or more users.
*
* @throws invalid_parameter_exception
* @param array $users An array of users to create.
* @return array An array of arrays
* @since Moodle 2.2
*/
public static function create_users($users)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/lib/weblib.php";
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();
self::validate_context($context);
require_capability('moodle/user:create', $context);
// Do basic automatic PARAM checks on incoming data, using params description.
// If any problems are found then exceptions are thrown with helpful error messages.
$params = self::validate_parameters(self::create_users_parameters(), array('users' => $users));
$availableauths = core_component::get_plugin_list('auth');
unset($availableauths['mnet']);
// These would need mnethostid too.
unset($availableauths['webservice']);
// We do not want new webservice users for now.
$availablethemes = core_component::get_plugin_list('theme');
$availablelangs = get_string_manager()->get_list_of_translations();
$transaction = $DB->start_delegated_transaction();
$userids = array();
$createpassword = false;
foreach ($params['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))) {
throw new invalid_parameter_exception('Username already exists: ' . $user['username']);
}
// Make sure auth is valid.
if (empty($availableauths[$user['auth']])) {
throw new invalid_parameter_exception('Invalid authentication type: ' . $user['auth']);
}
// Make sure lang is valid.
if (empty($availablelangs[$user['lang']])) {
throw new invalid_parameter_exception('Invalid language code: ' . $user['lang']);
}
// 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']).
throw new invalid_parameter_exception('Invalid theme: ' . $user['theme']);
}
// Make sure we have a password or have to create one.
if (empty($user['password']) && empty($user['createpassword'])) {
throw new invalid_parameter_exception('Invalid password: you must provide a password, or set createpassword.');
}
$user['confirmed'] = true;
$user['mnethostid'] = $CFG->mnet_localhost_id;
// Start of user info validation.
// Make sure we validate current user info as handled by current GUI. See user/editadvanced_form.php func validation().
if (!validate_email($user['email'])) {
throw new invalid_parameter_exception('Email address is invalid: ' . $user['email']);
} else {
if (empty($CFG->allowaccountssameemail) && $DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $CFG->mnet_localhost_id))) {
throw new invalid_parameter_exception('Email address already exists: ' . $user['email']);
}
}
// End of user info validation.
$createpassword = !empty($user['createpassword']);
unset($user['createpassword']);
if ($createpassword) {
$user['password'] = '';
$updatepassword = false;
} else {
$updatepassword = true;
}
// Create the user data now!
$user['id'] = user_create_user($user, $updatepassword, false);
// 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);
}
if ($createpassword) {
$userobject = (object) $user;
setnew_password_and_mail($userobject);
unset_user_preference('create_password', $userobject);
set_user_preference('auth_forcepasswordchange', 1, $userobject);
}
// Trigger event.
\core\event\user_created::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']);
//.........这里部分代码省略.........
开发者ID:wset,项目名称:moodle-local_extrauserlookups,代码行数:101,代码来源:externallib.php
示例10: isset
}
if (isset($usernew->userdepartment) || isset($usernew->usertitle)) {
$department = isset($usernew->userdepartment) ? $usernew->userdepartment : 0;
$title = isset($usernew->usertitle) ? $usernew->usertitle : 0;
assign_department_and_title_to_user($companyid, $department, $title, $usernew->id);
}
}
// Reload from db.
$usernew = $DB->get_record('user', array('id' => $usernew->id));
// Trigger events.
if ($usercreated) {
// Set default message preferences.
if (!message_set_default_message_preferences($usernew)) {
print_error('cannotsavemessageprefs', 'message');
}
$event = \core\event\user_created::create_from_userid($usernew->id);
$event->trigger();
} else {
$event = \core\event\user_updated::create(array('context' => $systemcontext, 'userid' => $usernew->id, 'relateduserid' => $USER->id));
$event->trigger();
}
if ($user->id == $USER->id) {
// Override old $USER session variable.
foreach ((array) $usernew as $variable => $value) {
$USER->{$variable} = $value;
}
if (!empty($USER->newadminuser)) {
unset($USER->newadminuser);
// Apply defaults again - some of them might depend on admin user info, backup, roles, etc..
admin_apply_default_settings(null, false);
// Redirect to admin/ to continue with installation.
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:editadvanced.php
示例11: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
public function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
$plainpassword = $user->password;
$user->password = hash_internal_user_password($user->password);
$user->mnethostid = $CFG->mnet_localhost_id;
if (empty($user->secret)) {
$user->secret = '';
}
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$firstname = strtolower($user->firstname);
$lastname = strtolower($user->lastname);
$initials = $firstname[0] . $lastname[0];
try {
$transaction = $DB->start_delegated_transaction();
do {
$username = sprintf($initials . "%04d", rand(1, 9999));
} while ($DB->get_record('user', array("username" => $username), 'id', IGNORE_MISSING));
$user->username = $username;
$userdetailstext = "Username: {$username}<br />Password: {$plainpassword}";
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainpassword);
// Save any custom profile field information.
$user->profile_field_typeofaccount = empty($user->profile_field_typeofaccount) ? 'student' : $user->profile_field_typeofaccount;
$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;
profile_save_data($user);
$record = new stdClass();
$record->studentuserid = $user->id;
$record->teacheruserid = $user->id;
switch ($user->profile_field_typeofaccount) {
case 'wceteacher':
$this->add_teacher($user->id);
break;
case 'adult':
case 'student':
default:
$this->add_student($user->id);
break;
}
// Trigger event.
\core\event\user_created::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;
}
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail, auth_email');
}
if ($notify) {
global $CFG, $PAGE, $OUTPUT;
$emailconfirm = get_string('emailconfirm');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($PAGE->course->fullname);
echo $OUTPUT->header();
notice(get_string('signup:emailconfirmsent:text', 'auth_watercorped', $userdetailstext), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:posttechguy,项目名称:moodle-meditrax-local_meditraxcohort,代码行数:75,代码来源:auth.php
示例12: user_signup
function user_signup($user, $notify = false)
{
global $CFG, $DB, $SESSION;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/enrol/token/lib.php';
$lang = empty($user->lang) ? $CFG->lang : $user->lang;
$site = get_site();
$supportuser = core_user::get_support_user();
$newpassword = generate_password();
// the token the user entered (which is now validated)
$tokenValue = $user->token;
$newuser = new stdClass();
$newuser->auth = 'token';
// since technially this auth plugin is a skin
$newuser->firstname = $user->firstname;
$newuser->lastname = $user->lastname;
$newuser->password = hash_internal_user_password($newpassword, false);
$newuser->policyagreed = 1;
// might need to put this in somewhere
$newuser->username = $user->email;
$newuser->email = $user->email;
$newuser->lastip = getremoteaddr();
$newuser->timecreated = time();
$newuser->timemodified = $newuser->timecreated;
$newuser->mnethostid = $CFG->mnet_localhost_id;
$newuser = self::truncate_user_obj($newuser);
if (($newuser->id = $DB->insert_record('user', $newuser)) === false) {
notice(get_string('signupfailure', 'auth_token'), $CFG->wwwroot);
return false;
}
$user = get_complete_user_data('id', $newuser->id);
\core\event\user_created::create_from_userid($user->id)->trigger();
// just the query part of post-login redirect
$params = empty($SESSION->wantsurl) === true ? '' : parse_url($SESSION->wantsurl, PHP_URL_QUERY);
$a = new stdClass();
$a->firstname = $user->firstname;
$a->lastname = $user->lastname;
$a->username = $user->username;
$a->password = $newpassword;
$a->sitename = format_string($site->fullname);
$a->link = $CFG->wwwroot . '/auth/token/login.php?' . $params;
$a->signoff = generate_email_signoff();
$message = (string) new lang_string('signup_userregoemail', 'auth_token', $a, $lang);
$subject = format_string($site->fullname) . ': ' . (string) new lang_string('newusernewpasswordsubj', '', $a, $lang);
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
email_to_user($user, $supportuser, $subject, $message);
// log the user in immediately
if (($user = authenticate_user_login($user->username, $newpassword)) === false || complete_user_login($user) == null) {
notice(get_string('autologinfailure', 'auth_token'), $CFG->wwwroot);
return false;
}
// now, actually DO the enrolment for this course / user
$token_plugin = new enrol_token_plugin();
$courseId = 0;
$return_to_url = empty($SESSION->wantsurl) === true ? $CFG->wwwroot : $SESSION->wantsurl;
$enrolled_ok = $token_plugin->doEnrolment($tokenValue, $courseId, $return_to_url);
if ($enrolled_ok == true) {
redirect($return_to_url);
}
return $enrolled_ok == true;
}
开发者ID:frumbert,项目名称:moodle-token-enrolment,代码行数:61,代码来源:auth.php
示例13: user_created
public static function user_created(\core\event\user_created $event)
{
global $CFG, $DB;
$sync_to_joomla = get_config('auth/joomdle', 'sync_to_joomla');
if (!$sync_to_joomla) {
return true;
}
$user = $event->get_record_snapshot('user', $event->objectid);
if ($user->auth != 'joomdle') {
return true;
}
$auth_joomdle = new auth_plugin_joomdle();
/*
$password_clear = '';
if (array_key_exists ('password', $_POST))
$password_clear = $_POST['password']; //Self registration
if ((array_key_exists ('newpassword', $_POST)) && (!$password_clear))
$password_clear = $_POST['newpassword']; //admin form
*/
/* Create user in Joomla */
$userinfo['username'] = $user->username;
/*
$userinfo['password'] = $password_clear;
$userinfo['password2'] = $password_clear;
*/
$userinfo['password'] = $user->password;
$userinfo['password2'] = $user->password;
$userinfo['name'] = $user->firstname . " " . $user->lastname;
$userinfo['email'] = $user->email;
$userinfo['firstname'] = $user->firstname;
$userinfo['lastname'] = $user->lastname;
$userinfo['city'] = $user->city;
$userinfo['country'] = $user->country;
$userinfo['lang'] = $user->lang;
$userinfo['timezone'] = $user->timezone;
$userinfo['phone1'] = $user->phone1;
$userinfo['phone2'] = $user->phone2;
$userinfo['address'] = $user->address;
$userinfo['description'] = $user->description;
$userinfo['institution'] = $user->institution;
$userinfo['url'] = $user->url;
$userinfo['icq'] = $user->icq;
$userinfo['skype'] = $user->skype;
$userinfo['aim'] = $user->aim;
$userinfo['yahoo'] = $user->yahoo;
$userinfo['msn'] = $user->msn;
$userinfo['idnumber'] = $user->idnumber;
$userinfo['department'] = $user->department;
$userinfo['picture'] = $user->picture;
$userinfo['lastnamephonetic'] = $user->lastnamephonetic;
$userinfo['firstnamephonetic'] = $user->firstnamephonetic;
$userinfo['middlename'] = $user->middlename;
$userinfo['alternatename'] = $user->alternatename;
$id = $user->id;
$usercontext = context_user::instance($id);
$context_id = $usercontext->id;
if ($user->picture) {
$userinfo['pic_url'] = $CFG->wwwroot . "/pluginfile.php/{$context_id}/user/icon/f1";
}
$userinfo['block'] = 0;
/* Custom fields */
$query = "SELECT f.id, d.data \n FROM {$CFG->prefix}user_info_field as f, {$CFG->prefix}user_info_data d \n WHERE f.id=d.fieldid and userid = ?";
$params = array($id);
$records = $DB->get_records_sql($query, $params);
$i = 0;
$userinfo['custom_fields'] = array();
foreach ($records as $field) {
$userinfo['custom_fields'][$i]['id'] = $field->id;
$userinfo['custom_fields'][$i]['data'] = $field->data;
$i++;
}
$auth_joomdle->call_method("createUser", $userinfo);
return true;
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:74,代码来源:locallib.php
示例14: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG, $DB, $SESSION;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
if (isset($SESSION->wantsurl)) {
$wantsurl = $SESSION->wantsurl;
}
$plainpassword = $user->password;
$user->password = hash_internal_user_password($user->password);
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$user->confirmed = 1;
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainpassword);
// Save any custom profile field information.
profile_save_data($user);
// Trigger event.
\core\event\user_created::create_from_userid($user->id)->trigger();
$thisuser = authenticate_user_login($user->username, $plainpassword, false, $errorcode);
if ($thisuser == false) {
print_error('authfailure');
} else {
complete_user_login($thisuser);
if (isset($wantsurl)) {
$urltogo = $wantsurl;
if (isset($_SESSION["fiaction"]) && isset($_SESSION["ficourseid"]) && is_numeric($_SESSION["ficourseid"]) && $_SESSION["fiaction"] == "enroll") {
$urltogo = $CFG->wwwroot . '/course/enrol.php?id=' . $_SESSION["ficourseid"];
unset($_SESSION['fiaction']);
unset($_SESSION['ficourseid']);
unset($SESSION->wantsurl);
}
} else {
$urltogo = $CFG->wwwroot . '/';
}
redirect($urltogo);
}
// if ($notify) {
// global $CFG, $PAGE, $OUTPUT;
// $emailconfirm = get_string('emailconfirm');
// $PAGE->navbar->add($emailconfirm);
// $PAGE->set_title($emailconfirm);
// $PAGE->set_heading($PAGE->course->fullname);
// echo $OUTPUT->header();
// notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
// } else {
// return true;
// }
}
开发者ID:TheFridayInstitute,项目名称:moodle-auth_fiemail,代码行数:57,代码来源:auth.php
示例15: user_create_user
/**
* Creates a user
*
* @throws moodle_exception
* @param stdClass $user user to create
* @param bool $updatepassword if true, authentication plugin will update password.
* @param bool $triggerevent set false if user_created event should not be triggred.
* This will not affect user_password_updated event triggering.
* @return int id of the newly created user
*/
function user_create_user($user, $updatepassword = true, $triggerevent = true)
{
global $DB;
// Set the timecreate field to the current time.
if (!is_object($user)) {
$user = (object) $user;
}
// Check username.
if ($user->username !== core_text::strtolower($user->username)) {
throw new moodle_exception('usernamelowercase');
} else {
if ($user->username !== core_user::clean_field($user->username, 'username')) {
throw new moodle_exception('invalidusername');
}
}
// Save the password in a temp value for later.
if ($updatepassword && isset($user->password)) {
// Check password toward the password policy.
if (!check_password_policy($user->password, $errmsg)) {
throw new moodle_exception($errmsg);
}
$userpassword = $user->password;
unset($user->password);
}
// Apply default values for user preferences that are stored in users table.
if (!isset($user->calendartype)) {
$user->calendartype = core_user::get_property_default('calendartype');
}
if (!isset($user->maildisplay)) {
$user->maildisplay = core_user::get_property_default('maildisplay');
}
if (!isset($user->mailformat)) {
$user->mailformat = core_user::get_property_default('mailformat');
}
if (!isset($user->maildigest)) {
$user->maildigest = core_user::get_property_default('maildigest');
}
if (!isset($user->autosubscribe)) {
$user->autosubscribe = core_user::get_property_default('autosubscribe');
}
if (!isset($user->trackforums)) {
$user->trackforums = core_user::get_property_default('trackforums');
}
if (!isset($user->lang)) {
$user->lang = core_user::get_property_default('lang');
}
$user->timecreated = time();
$user->timemodified = $user->timecreated;
// Validate user data object.
$uservalidation = core_user::validate($user);
if ($uservalidation !== true) {
foreach ($uservalidation as $field => $message) {
debugging("The property '{$field}' has invalid data and has been cleaned.", DEBUG_DEVELOPER);
$user->{$field} = core_user::clean_field($user->{$field}, $field);
}
}
// Insert the user into the database.
$newuserid = $DB->insert_record('user', $user);
// Create USER context for this user.
$usercontext = context_user::instance($newuserid);
// Update user password if necessary.
if (isset($userpassword)) {
// Get full database user row, in case auth is default.
$newuser = $DB->get_record('user', array('id' => $newuserid));
$authplugin = get_auth_plugin($newuser->auth);
$authplugin->user_update_password($newuser, $userpassword);
}
// Trigger event If required.
if ($triggerevent) {
\core\event\user_created::create_from_userid($newuserid)->trigger();
}
return $newuserid;
}
开发者ID:dg711,项目名称:moodle,代码行数:83,代码来源:lib.php
示例16: sync_users
//.........这里部分代码省略.........
if ($this->config->{$key} === 'onlogin') {
array_push($updatekeys, $match[1]);
// The actual key name.
}
}
}
unset($all_keys);
unset($key);
// Only go ahead if we actually have fields to update locally.
if (!empty($updatekeys)) {
list($in_sql, $params) = $DB->get_in_or_equal($userlist, SQL_PARAMS_NAMED, 'u', true);
$params['authtype'] = $this->authtype;
$sql = "SELECT u.id, u.username\n FROM {user} u\n WHERE u.auth=:authtype AND u.deleted=0 AND u.username {$in_sql}";
if ($update_users = $DB->get_records_sql($sql, $params)) {
$trace->output("User entries to update: " . count($update_users));
foreach ($update_users as $user) {
if ($this->update_user_record($user->username, $updatekeys)) {
$trace->output(get_string('auth_dbupdatinguser', 'auth_db', array('name' => $user->username, 'id' => $user->id)), 1);
} else {
$trace->output(get_string('auth_dbupdatinguser', 'auth_db', array('name' => $user->username, 'id' => $user->id)) . " - " . get_string('skipped'), 1);
}
}
unset($update_users);
}
}
}
// Create missing accounts.
// NOTE: this is very memory intensive and generally inefficient.
$suspendselect = "";
if ($this->config->removeuser == AUTH_REMOVEUSER_SUSPEND) {
$suspendselect = "AND u.suspended = 0";
}
$sql = "SELECT u.id, u.username\n FROM {user} u\n WHERE u.auth=:authtype AND u.deleted='0' AND mnethostid=:mnethostid {$suspendselect}";
$users = $DB->get_records_sql($sql, array('authtype' => $this->authtype, 'mnethostid' => $CFG->mnet_localhost_id));
// Simplify down to usernames.
$usernames = array();
if (!empty($users)) {
foreach ($users as $user) {
array_push($usernames, $user->username);
}
unset($users);
}
$add_users = array_diff($userlist, $usernames);
unset($usernames);
if (!empty($add_users)) {
$trace->output(get_string('auth_dbuserstoadd', 'auth_db', count($add_users)));
// Do not use transactions around this foreach, we want to skip problematic users, not revert everything.
foreach ($add_users as $user) {
$username = $user;
if ($this->config->removeuser == AUTH_REMOVEUSER_SUSPEND) {
if ($old_user = $DB->get_record('user', array('username' => $username, 'deleted' => 0, 'suspended' => 1, 'm
|
请发表评论