mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-13811 Completed the required changes. Also added a "Cancel email change" link. Merging from MOODLE_19_STABLE
This commit is contained in:
parent
9da3dfa4ac
commit
d6ace123f0
@ -50,6 +50,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
$temp->add(new admin_setting_configtext('minpasswordupper', get_string('minpasswordupper', 'admin'), get_string('configminpasswordupper', 'admin'), 1, PARAM_INT));
|
||||
$temp->add(new admin_setting_configtext('minpasswordnonalphanum', get_string('minpasswordnonalphanum', 'admin'), get_string('configminpasswordnonalphanum', 'admin'), 1, PARAM_INT));
|
||||
$temp->add(new admin_setting_configcheckbox('disableuserimages', get_string('disableuserimages', 'admin'), get_string('configdisableuserimages', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('emailchangeconfirmation', get_string('emailchangeconfirmation', 'admin'), get_string('configemailchangeconfirmation', 'admin'), 0));
|
||||
$ADMIN->add('security', $temp);
|
||||
|
||||
|
||||
|
@ -98,6 +98,7 @@ $string['configdocroot'] = 'Defines the path to the Moodle Docs. You can change
|
||||
$string['configdoctonewwindow'] = 'If you enable this, then links to Moodle Docs will be shown in a new window.';
|
||||
$string['configeditorfontlist'] = 'Select the fonts that should appear in the editor\'s drop-down list.';
|
||||
$string['configeditordictionary'] = 'This value will be used if aspell doesn\'t have dictionary for users own language.';
|
||||
$string['configemailchangeconfirmation'] = 'Require an email confirmation step when users change their email address in their profile.';
|
||||
$string['configemoticons'] = 'Change the code on the left that relates to the name of the emoticon on the right. To add new emoticons, add a code and a name, then add an image as name.gif in /pix/s.';
|
||||
$string['configenableajax'] = 'This setting allows you to control the use of AJAX (advanced client/server interfaces using Javascript) across the whole site. With this setting enabled users can still make a choice in their profile, otherwise AJAX is disabled for everybody.';
|
||||
$string['configdisablecourseajax'] = 'Do not use AJAX when editing main course pages.';
|
||||
@ -319,6 +320,7 @@ $string['editorkillword'] = 'Word format filter';
|
||||
$string['editorspellinghelp'] = 'Enable or disable spell-checking. When enabled, <strong>aspell</strong> must be installed on the server.';
|
||||
$string['editorspelling'] = 'Editor spelling';
|
||||
$string['editstrings'] = 'Edit words or phrases';
|
||||
$string['emailchangeconfirmation'] = 'Email change confirmation';
|
||||
$string['emoticons'] = 'Emoticons';
|
||||
$string['emptysettingvalue'] = 'Empty';
|
||||
$string['enableajax'] = 'Enable AJAX';
|
||||
|
@ -111,13 +111,28 @@ $string['auth_dbdebugauthdbhelp'] = 'Debug ADOdb connection to external database
|
||||
$string['auth_dbchangepasswordurl_key'] = 'Password-change URL';
|
||||
|
||||
// Email plugin
|
||||
$string['auth_emailchangecancel'] = 'Cancel email change';
|
||||
$string['auth_emailchangepending'] = 'Change pending. Open the link sent to you at $a->preference_newemail.';
|
||||
$string['auth_emaildescription'] = 'Email confirmation is the default authentication method. When the user signs up, choosing their own new username and password, a confirmation email is sent to the user\'s email address. This email contains a secure link to a page where the user can confirm their account. Future logins just check the username and password against the stored values in the Moodle database.';
|
||||
$string['auth_emailnowexists'] = 'The email address you tried to assign to your profile has been assigned to someone else since your original request. Your request for change of email address is hereby cancelled, but you may try again with a different address.';
|
||||
$string['auth_emailtitle'] = 'Email-based self-registration';
|
||||
$string['auth_emailnoinsert'] = 'Could not add your record to the database!';
|
||||
$string['auth_emailnoemail'] = 'Tried to send you an email but failed!';
|
||||
$string['auth_emailrecaptcha'] = 'Adds a visual/audio confirmation form element to the signup page for email self-registering users. This protects your site against spammers and contributes to a worthwhile cause. See http://recaptcha.net/learnmore.html for more details.';
|
||||
$string['auth_emailrecaptcha_key'] = 'Enable reCAPTCHA element';
|
||||
$string['auth_emailsettings'] = 'Settings';
|
||||
$string['auth_emailupdatemessage'] = 'Dear $a->fullname,
|
||||
|
||||
You have requested a change of your email address for your user account at $a->site. Please open the following URL in your browser in order to confirm this change.
|
||||
|
||||
$a->url';
|
||||
$string['auth_emailupdatetitle'] = 'Confirmation of email update at $a->site';
|
||||
$string['auth_invalidnewemailkey'] = 'Error: if you are trying to confirm a change of email address, you may have made a mistake in copying the URL we sent you by email. Please copy the address and try again.';
|
||||
$string['auth_emailupdatesuccess'] = 'Your email address was successfully updated to $a->email.';
|
||||
$string['auth_outofnewemailupdateattempts'] = 'You have run out of allowed attempts to update your email address. Your update request has been cancelled.';
|
||||
$string['auth_emailupdate'] = 'Email address update';
|
||||
$string['auth_changingemailaddress'] = 'You have requested a change of email address, from $a->oldemail to $a->newemail. For security reasons, we are sending you an email message at the new address to confirm that it belongs to you. Your email address will be updated as soon as you open the URL sent to you in that message.';
|
||||
|
||||
|
||||
// FirstClass plugin
|
||||
$string['auth_fccreators'] = 'List of groups whose members are allowed to create new courses. Separate multiple groups with \';\'. Names must be spelled exactly as on FirstClass server. System is case-sensitive.';
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
$userid = optional_param('id', $USER->id, PARAM_INT); // user id
|
||||
$course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
|
||||
$cancelemailchange = optional_param('cancelemailchange', false, PARAM_INT); // course id (defaults to Site)
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id'=>$course))) {
|
||||
print_error('invalidcourseid');
|
||||
@ -34,6 +35,16 @@
|
||||
print_error('invaliduserid');
|
||||
}
|
||||
|
||||
// Process email change cancellation
|
||||
if ($cancelemailchange) {
|
||||
useredit_load_preferences($user);
|
||||
$user->preference_newemail = null;
|
||||
$user->preference_newemailkey = null;
|
||||
$user->preference_newemailattemptsleft = null;
|
||||
useredit_update_user_preference($user);
|
||||
}
|
||||
|
||||
|
||||
// Guest can not be edited
|
||||
if (isguestuser($user)) {
|
||||
print_error('guestnoeditprofile');
|
||||
@ -89,10 +100,29 @@
|
||||
$userform = new user_edit_form();
|
||||
$userform->set_data($user);
|
||||
|
||||
$email_changed = false;
|
||||
|
||||
if ($usernew = $userform->get_data()) {
|
||||
|
||||
add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
|
||||
|
||||
$email_changed_html = '';
|
||||
|
||||
if ($CFG->emailchangeconfirmation) {
|
||||
// Handle change of email carefully for non-trusted users
|
||||
if ($user->email != $usernew->email && !has_capability('moodle/user:update', $systemcontext)) {
|
||||
$a = new stdClass();
|
||||
$a->newemail = $usernew->preference_newemail = $usernew->email;
|
||||
$usernew->preference_newemailkey = random_string(20);
|
||||
$usernew->preference_newemailattemptsleft = 3;
|
||||
$a->oldemail = $usernew->email = $user->email;
|
||||
|
||||
$email_changed_html = print_box(get_string('auth_changingemailaddress', 'auth', $a), 'generalbox', 'notice', true);
|
||||
$email_changed_html .= print_continue("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id", true);
|
||||
$email_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
$authplugin = get_auth_plugin($user->auth);
|
||||
|
||||
$usernew->timemodified = time();
|
||||
@ -130,6 +160,24 @@
|
||||
// save custom profile fields data
|
||||
profile_save_data($usernew);
|
||||
|
||||
// If email was changed, send confirmation email now
|
||||
if ($email_changed && $CFG->emailchangeconfirmation) {
|
||||
$temp_user = fullclone($user);
|
||||
$temp_user->email = $usernew->preference_newemail;
|
||||
|
||||
$a = new stdClass();
|
||||
$a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id;
|
||||
$a->site = $SITE->fullname;
|
||||
$a->fullname = fullname($user, true);
|
||||
|
||||
$emailupdatemessage = get_string('auth_emailupdatemessage', 'auth', $a);
|
||||
$emailupdatetitle = get_string('auth_emailupdatetitle', 'auth', $a);
|
||||
|
||||
if(!$mail_results = email_to_user($temp_user, get_admin(), $emailupdatetitle, $emailupdatemessage)) {
|
||||
die("could not send email!");
|
||||
}
|
||||
}
|
||||
|
||||
if ($USER->id == $user->id) {
|
||||
// Override old $USER session variable if needed
|
||||
$usernew = $DB->get_record('user', array('id'=>$user->id)); // reload from db
|
||||
@ -138,8 +186,11 @@
|
||||
}
|
||||
}
|
||||
events_trigger('user_updated', $usernew);
|
||||
|
||||
if (!$email_changed || !$CFG->emailchangeconfirmation) {
|
||||
redirect("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Display page header
|
||||
@ -163,8 +214,12 @@
|
||||
$currenttab = 'editprofile';
|
||||
require('tabs.php');
|
||||
|
||||
if ($email_changed) {
|
||||
echo $email_changed_html;
|
||||
} else {
|
||||
/// Finally display THE form
|
||||
$userform->display();
|
||||
}
|
||||
|
||||
/// and proper footer
|
||||
print_footer($course);
|
||||
|
@ -59,7 +59,10 @@ function useredit_update_interests($user, $csv_tag_names) {
|
||||
}
|
||||
|
||||
function useredit_shared_definition(&$mform) {
|
||||
global $CFG;
|
||||
global $CFG, $USER, $DB;
|
||||
|
||||
$user = $DB->get_record('user', array('id' => $USER->id));
|
||||
useredit_load_preferences($user);
|
||||
|
||||
$strrequired = get_string('required');
|
||||
|
||||
@ -80,8 +83,16 @@ function useredit_shared_definition(&$mform) {
|
||||
$mform->addRule('lastname', $strrequired, 'required', null, 'client');
|
||||
$mform->setType('lastname', PARAM_NOTAGS);
|
||||
|
||||
// Do not show email field if change confirmation is pending
|
||||
if ($CFG->emailchangeconfirmation && !empty($user->preference_newemail)) {
|
||||
$notice = get_string('auth_emailchangepending', 'auth', $user);
|
||||
$notice .= '<br /><a href="edit.php?cancelemailchange=1&id='.$user->id.'">'
|
||||
. get_string('auth_emailchangecancel', 'auth') . '</a>';
|
||||
$mform->addElement('static', 'emailpending', get_string('email'), $notice);
|
||||
} else {
|
||||
$mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
|
||||
$mform->addRule('email', $strrequired, 'required', null, 'client');
|
||||
}
|
||||
|
||||
$choices = array();
|
||||
$choices['0'] = get_string('emaildisplayno');
|
||||
|
65
user/emailupdate.php
Executable file
65
user/emailupdate.php
Executable file
@ -0,0 +1,65 @@
|
||||
<?php // $Id$
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$key = required_param('key', PARAM_ALPHANUM);
|
||||
$id = required_param('id', PARAM_INT);
|
||||
|
||||
if (!$user = $DB->get_record('user', array('id' => $id))) {
|
||||
error("Unknown user ID");
|
||||
}
|
||||
|
||||
$preferences = get_user_preferences(null, null, $id);
|
||||
$a = new stdClass();
|
||||
$a->fullname = fullname($user, true);
|
||||
$stremailupdate = get_string('auth_emailupdate', 'auth', $a);
|
||||
print_header(format_string($SITE->fullname) . ": $stremailupdate", format_string($SITE->fullname) . ": $stremailupdate");
|
||||
|
||||
$cancel_email_update = false;
|
||||
|
||||
if (empty($preferences['newemailattemptsleft'])) {
|
||||
redirect("$CFG->wwwroot/user/view.php?id=$user->id");
|
||||
|
||||
} elseif ($preferences['newemailattemptsleft'] < 1) {
|
||||
$cancel_email_update = true;
|
||||
$stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth');
|
||||
print_box($stroutofattempts, 'center');
|
||||
|
||||
} elseif ($key == $preferences['newemailkey']) {
|
||||
$user->email = $preferences['newemail'];
|
||||
|
||||
// Detect duplicate before saving
|
||||
if ($DB->get_record('user', array('email' => $user->email))) {
|
||||
$stremailnowexists = get_string('auth_emailnowexists', 'auth');
|
||||
print_box($stremailnowexists, 'center');
|
||||
$cancel_email_update = true;
|
||||
print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
|
||||
} else {
|
||||
// update user email
|
||||
if (!$DB->set_field('user', 'email', $user->email, array('id' => $user->id))) {
|
||||
error('Error updating user record');
|
||||
|
||||
} else {
|
||||
events_trigger('user_updated', $user);
|
||||
$stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth', $user);
|
||||
print_box($stremailupdatesuccess, 'center');
|
||||
print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
|
||||
|
||||
$cancel_email_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$preferences['newemailattemptsleft']--;
|
||||
set_user_preference('newemailattemptsleft', $preferences['newemailattemptsleft'], $user->id);
|
||||
$strinvalidkey = get_string('auth_invalidnewemailkey', 'auth');
|
||||
print_box($strinvalidkey, 'center');
|
||||
}
|
||||
|
||||
if ($cancel_email_update) {
|
||||
require_once($CFG->dirroot . '/user/editlib.php');
|
||||
$user->preference_newemail = null;
|
||||
$user->preference_newemailkey = null;
|
||||
$user->preference_newemailattemptsleft = null;
|
||||
useredit_update_user_preference($user);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2008070300; // YYYYMMDD = date of the last version bump
|
||||
$version = 2008070500; // YYYYMMDD = date of the last version bump
|
||||
// XX = daily increments
|
||||
|
||||
$release = '2.0 dev (Build: 20080705)'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user