]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13811 Completed the required changes. Also added a "Cancel email change" link...
authornicolasconnault <nicolasconnault>
Sat, 5 Jul 2008 14:28:13 +0000 (14:28 +0000)
committernicolasconnault <nicolasconnault>
Sat, 5 Jul 2008 14:28:13 +0000 (14:28 +0000)
admin/settings/security.php
lang/en_utf8/admin.php
lang/en_utf8/auth.php
user/edit.php
user/editlib.php
user/emailupdate.php [new file with mode: 0755]
version.php

index b82cdb161ca5d998df7d022a38fb6f9a4f35f6ec..b867ff756b6959de16c82288e1aad5cf62134476 100644 (file)
@@ -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);
 
 
index dc27e8a95962069333d8f059888f4b0a2a2bbc8a..5c6d2056cc0199d2b294c4f53746e4952243f6cc 100644 (file)
@@ -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';
index 6fd73b8a6824b89e12f35bcaa78e3cee40406743..2a3c1651fd8440041704d31db98014abed91dab1 100644 (file)
@@ -1,4 +1,4 @@
-<?php // $Id$ 
+<?php // $Id$
       // auth.php - created with Moodle 1.5 UNSTABLE DEVELOPMENT (2005010100)
 
 
@@ -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.';
@@ -192,11 +207,11 @@ $string['auth_ldap_user_type'] = 'Select how users are stored in LDAP. This sett
 $string['auth_ldap_version'] = 'The version of the LDAP protocol your server is using.';
 $string['auth_ldapdescription'] = 'This method provides authentication against an external LDAP server.
 
-                                  If the given username and password are valid, Moodle creates a new user 
+                                  If the given username and password are valid, Moodle creates a new user
 
-                                  entry in its database. This module can read user attributes from LDAP and prefill 
+                                  entry in its database. This module can read user attributes from LDAP and prefill
 
-                                  wanted fields in Moodle.  For following logins only the username and 
+                                  wanted fields in Moodle.  For following logins only the username and
 
                                   password are checked.';
 $string['auth_ldap_ldap_encoding_key'] = 'LDAP encoding';
@@ -321,7 +336,7 @@ $string['auth_shib_changepasswordurl'] = 'Password-change URL';
 $string['auth_shibboleth_login_long'] = 'Login to Moodle via Shibboleth';
 $string['auth_shibboleth_select_organization'] = 'For authentication via Shibboleth, please select your organization from the drop down list:';
 $string['auth_shibboleth_contact_administrator'] = 'In case you are not associated with the given organizations and you need access to a course on this server, please contact the';
-$string['auth_shibboleth_select_member'] = 'I\'m a member of ...'; 
+$string['auth_shibboleth_select_member'] = 'I\'m a member of ...';
 $string['auth_shibboleth_errormsg'] ='Please select the organization you are member of!';
 $string['auth_shib_no_organizations_warning'] ='If you want to use the integrated WAYF service, you must provide a coma-separated list of Identity Provider entityIDs, their names and optionally a session initiator.';
 
index 46ea23c061f8da1b16291570bb2d10acc7195faa..2298e7963ab18b700f3c5b42ca253c51dc35db2d 100644 (file)
@@ -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');
         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)) {  
+    if (isguestuser($user)) {
         print_error('guestnoeditprofile');
     }
 
     $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&amp;course=$course->id", true);
+                $email_changed = true;
+            }
+        }
+
         $authplugin = get_auth_plugin($user->auth);
 
         $usernew->timemodified = time();
         // 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
             }
         }
         events_trigger('user_updated', $usernew);
-        redirect("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id");
+
+        if (!$email_changed || !$CFG->emailchangeconfirmation) {
+            redirect("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id");
+        }
     }
 
 
     $currenttab = 'editprofile';
     require('tabs.php');
 
-/// Finally display THE form
-    $userform->display();
+    if ($email_changed) {
+        echo $email_changed_html;
+    } else {
+    /// Finally display THE form
+        $userform->display();
+    }
 
 /// and proper footer
     print_footer($course);
index 0faade9f69718829e302504b3faa905135ca64bf..d67d17865049c075eb1d76612d905294e451620c 100644 (file)
@@ -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);
 
-    $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
-    $mform->addRule('email', $strrequired, 'required', null, 'client');
+    // 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&amp;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');
@@ -225,9 +236,9 @@ function useredit_shared_definition(&$mform) {
         $mform->addElement('header', 'moodle_interests', get_string('interests'));
         $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"');
         $mform->setHelpButton('interests', array('interestslist', get_string('helpinterestslist'),
-                          false, true, false)); 
+                          false, true, false));
     }
-    
+
     /// Moodle optional fields
     $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
     $mform->setAdvanced('moodle_optional');
@@ -267,8 +278,8 @@ function useredit_shared_definition(&$mform) {
 
     $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
     $mform->setType('address', PARAM_MULTILANG);
-    
-    
+
+
 }
 
 ?>
diff --git a/user/emailupdate.php b/user/emailupdate.php
new file mode 100755 (executable)
index 0000000..93da578
--- /dev/null
@@ -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);
+}
index c4b8899068650e776a7a2140b763a38f694539a8..7cdf812657c9da1c154cec8d57abc2569f43ca19 100644 (file)
@@ -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