Merge branch 'MDL-17943_master' of git://github.com/markn86/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 6 Jun 2018 18:23:57 +0000 (20:23 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 6 Jun 2018 18:23:57 +0000 (20:23 +0200)
admin/user.php
lang/en/moodle.php
login/index.php
login/lib.php

index 0caf98f..f6ab61f 100644 (file)
@@ -19,6 +19,7 @@
     $suspend      = optional_param('suspend', 0, PARAM_INT);
     $unsuspend    = optional_param('unsuspend', 0, PARAM_INT);
     $unlock       = optional_param('unlock', 0, PARAM_INT);
+    $resendemail  = optional_param('resendemail', 0, PARAM_INT);
 
     admin_externalpage_setup('editusers');
 
@@ -37,6 +38,7 @@
     $strunsuspend = get_string('unsuspenduser', 'admin');
     $strunlock = get_string('unlockaccount', 'admin');
     $strconfirm = get_string('confirm');
+    $strresendemail = get_string('resendemail');
 
     $returnurl = new moodle_url('/admin/user.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage, 'page'=>$page));
 
             redirect($returnurl, get_string('usernotconfirmed', '', fullname($user, true)));
         }
 
+    } else if ($resendemail && confirm_sesskey()) {
+        if (!$user = $DB->get_record('user', ['id' => $resendemail, 'mnethostid' => $CFG->mnet_localhost_id, 'deleted' => 0])) {
+            print_error('nousers');
+        }
+
+        // Prevent spamming users who are already confirmed.
+        if ($user->confirmed) {
+            print_error('alreadyconfirmed');
+        }
+
+        $returnmsg = get_string('emailconfirmsentsuccess');
+        $messagetype = \core\output\notification::NOTIFY_SUCCESS;
+        if (!send_confirmation_email($user)) {
+            $returnmsg = get_string('emailconfirmsentfailure');
+            $messagetype = \core\output\notification::NOTIFY_ERROR;
+        }
+
+        redirect($returnurl, $returnmsg, null, $messagetype);
     } else if ($delete and confirm_sesskey()) {              // Delete a selected user, after confirmation
         require_capability('moodle/user:delete', $sitecontext);
 
                 } else {
                     $lastcolumn = "<span class=\"dimmed_text\">".get_string('confirm')."</span>";
                 }
+
+                $lastcolumn .= ' | ' . html_writer::link(new moodle_url($returnurl,
+                    [
+                        'resendemail' => $user->id,
+                        'sesskey' => sesskey()
+                    ]
+                ), $strresendemail);
             }
 
             if ($user->lastaccess) {
index e83cbf3..efd628b 100644 (file)
@@ -266,7 +266,7 @@ $string['configuration'] = 'Configuration';
 $string['confirm'] = 'Confirm';
 $string['confirmdeletesection'] = 'Are you absolutely sure you want to completely delete "{$a}" and all the activities it contains?';
 $string['confirmed'] = 'Your registration has been confirmed';
-$string['confirmednot'] = 'Your registration has not yet been confirmed!';
+$string['confirmednot'] = 'Your registration has not yet been confirmed. Please check your mailbox for a confirmation email.';
 $string['confirmcheckfull'] = 'Are you absolutely sure you want to confirm {$a} ?';
 $string['confirmcoursemove'] = 'Are you sure you want to move this course ({$a->course}) into this category ({$a->category})?';
 $string['considereddigitalminor'] = 'You are considered to be a digital minor.';
@@ -602,10 +602,13 @@ line at the top of your web browser window.
 
 If you need help, please contact the site administrator,
 {$a->admin}';
+$string['emailconfirmationresend'] = 'Resend confirmation email';
 $string['emailconfirmationsubject'] = '{$a}: account confirmation';
 $string['emailconfirmsent'] = '<p>An email should have been sent to your address at <b>{$a}</b></p>
    <p>It contains easy instructions to complete your registration.</p>
    <p>If you continue to have difficulty, contact the site administrator.</p>';
+$string['emailconfirmsentfailure'] = 'Confirmation email failed to send';
+$string['emailconfirmsentsuccess'] = 'Confirmation email sent successfully';
 $string['emaildigest'] = 'Email digest type';
 $string['emaildigest_help'] = 'This is the daily digest setting that forums will use by default.
 
@@ -1286,7 +1289,7 @@ $string['moveselectedcoursesto'] = 'Move selected courses to...';
 $string['movetoanotherfolder'] = 'Move to another folder';
 $string['moveup'] = 'Move up';
 $string['msnid'] = 'MSN ID';
-$string['mustconfirm'] = 'You need to confirm your login';
+$string['mustconfirm'] = 'You need to confirm your account';
 $string['mustchangepassword'] = 'The new password must be different than the current one';
 $string['mycourses'] = 'My courses';
 $string['myfiles'] = 'My private files';
@@ -1648,6 +1651,7 @@ $string['requestedcourses'] = 'Requested courses';
 $string['requestreason'] = 'Reason for course request';
 $string['required'] = 'Required';
 $string['requirespayment'] = 'This course requires payment for access';
+$string['resendemail'] = 'Resend email';
 $string['reset'] = 'Reset';
 $string['resetcomponent'] = 'Component';
 $string['resetcourse'] = 'Reset course';
index 9ab9abb..923cb43 100644 (file)
@@ -31,6 +31,7 @@ redirect_if_major_upgrade_required();
 
 $testsession = optional_param('testsession', 0, PARAM_INT); // test session works properly
 $anchor      = optional_param('anchor', '', PARAM_RAW);      // Used to restore hash anchor to wantsurl.
+$resendconfirmemail = optional_param('resendconfirmemail', false, PARAM_BOOL);
 
 $context = context_system::instance();
 $PAGE->set_url("$CFG->wwwroot/login/index.php");
@@ -172,7 +173,22 @@ if ($frm and isset($frm->username)) {                             // Login WITH
             $PAGE->set_heading($site->fullname);
             echo $OUTPUT->header();
             echo $OUTPUT->heading(get_string("mustconfirm"));
+            if ($resendconfirmemail) {
+                if (!send_confirmation_email($user)) {
+                    echo $OUTPUT->notification(get_string('emailconfirmsentfailure'), \core\output\notification::NOTIFY_ERROR);
+                } else {
+                    echo $OUTPUT->notification(get_string('emailconfirmsentsuccess'), \core\output\notification::NOTIFY_SUCCESS);
+                }
+            }
             echo $OUTPUT->box(get_string("emailconfirmsent", "", $user->email), "generalbox boxaligncenter");
+            $resendconfirmurl = new moodle_url('/login/index.php',
+                [
+                    'username' => $frm->username,
+                    'password' => $frm->password,
+                    'resendconfirmemail' => true
+                ]
+            );
+            echo $OUTPUT->single_button($resendconfirmurl, get_string('emailconfirmationresend'));
             echo $OUTPUT->footer();
             die;
         }
index 8927e03..eb29ae1 100644 (file)
@@ -361,6 +361,7 @@ function core_login_validate_forgot_password_data($data) {
         } else {
             if ($user = get_complete_user_data('email', $data['email'])) {
                 if (empty($user->confirmed)) {
+                    send_confirmation_email($user);
                     $errors['email'] = get_string('confirmednot');
                 }
             }
@@ -372,6 +373,7 @@ function core_login_validate_forgot_password_data($data) {
     } else {
         if ($user = get_complete_user_data('username', $data['username'])) {
             if (empty($user->confirmed)) {
+                send_confirmation_email($user);
                 $errors['email'] = get_string('confirmednot');
             }
         }