diff --git a/auth/classes/output/login.php b/auth/classes/output/login.php index c2bb00b15ac..03a62f8f1dc 100644 --- a/auth/classes/output/login.php +++ b/auth/classes/output/login.php @@ -53,6 +53,8 @@ class login implements renderable, templatable { public $cookieshelpicon; /** @var string The error message, if any. */ public $error; + /** @var string The info message, if any. */ + public $info; /** @var moodle_url Forgot password URL. */ public $forgotpasswordurl; /** @var array Additional identify providers, contains the keys 'url', 'name' and 'icon'. */ @@ -131,6 +133,15 @@ class login implements renderable, templatable { $this->error = $error; } + /** + * Set the info message. + * + * @param string $info The info message. + */ + public function set_info(string $info): void { + $this->info = $info; + } + public function export_for_template(renderer_base $output) { $identityproviders = \auth_plugin_base::prepare_identity_providers_for_output($this->identityproviders, $output); @@ -142,6 +153,7 @@ class login implements renderable, templatable { $data->cansignup = $this->cansignup; $data->cookieshelpicon = $this->cookieshelpicon->export_for_template($output); $data->error = $this->error; + $data->info = $this->info; $data->forgotpasswordurl = $this->forgotpasswordurl->out(false); $data->hasidentityproviders = !empty($this->identityproviders); $data->hasinstructions = !empty($this->instructions) || $this->cansignup; diff --git a/lang/en/admin.php b/lang/en/admin.php index c8b077ba046..cfacbfeaea0 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -24,6 +24,8 @@ $string['accessdenied'] = 'Access denied'; $string['accounts'] = 'Accounts'; +$string['accountunlocked'] = 'Your account has been unlocked successfully. You may now login below.'; +$string['accountlocked'] = 'Your account has been locked. An unlock link has been sent to the email address associated with your account.'; $string['addcategory'] = 'Add a category'; $string['additionalhtml'] = 'Additional HTML'; $string['additionalhtml_heading'] = 'Additional HTML to be added to every page.'; diff --git a/lib/authlib.php b/lib/authlib.php index 2d742cdc5c3..11419edffdf 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -1018,12 +1018,18 @@ function login_lock_account($user) { * Unlock user account and reset timers. * * @param stdClass $user + * @param bool $notify Notify the user their account has been unlocked. */ -function login_unlock_account($user) { +function login_unlock_account($user, bool $notify = false) { + global $SESSION; + unset_user_preference('login_lockout', $user); unset_user_preference('login_failed_count', $user); unset_user_preference('login_failed_last', $user); + if ($notify) { + $SESSION->logininfomsg = get_string('accountunlocked', 'admin'); + } // Note: do not clear the lockout secret because user might click on the link repeatedly. } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 794bad1a051..c37888065ee 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4246,7 +4246,7 @@ function guest_user() { * @return stdClass|false A {@link $USER} object or false if error */ function authenticate_user_login($username, $password, $ignorelockout=false, &$failurereason=null, $logintoken=false) { - global $CFG, $DB, $PAGE; + global $CFG, $DB, $PAGE, $SESSION; require_once("$CFG->libdir/authlib.php"); if ($user = get_complete_user_data('username', $username, $CFG->mnet_localhost_id)) { @@ -4351,6 +4351,8 @@ function authenticate_user_login($username, $password, $ignorelockout=false, &$f $event->trigger(); error_log('[client '.getremoteaddr()."] $CFG->wwwroot Login lockout: $username ".$_SERVER['HTTP_USER_AGENT']); + $SESSION->loginerrormsg = get_string('accountlocked', 'admin'); + return false; } } else { diff --git a/lib/templates/loginform.mustache b/lib/templates/loginform.mustache index c4f656864f3..fb48aa38e60 100644 --- a/lib/templates/loginform.mustache +++ b/lib/templates/loginform.mustache @@ -26,6 +26,7 @@ * cansignup - Signup allowed?, * cookieshelpicon - cookies help icon details * error - Any errors in the form?, + * info - Info notification to display, * forgotpasswordurl - Forgot password url, * hasidentityproviders - Flag, set to true to hide identity providers, * hasinstructions - Flag, set to true to show instructions, @@ -75,6 +76,7 @@ "ltr": true }, "error": "", + "info": "", "forgotpasswordurl": "http://localhost/stable_master/login/forgot_password.php", "hasidentityproviders": false, "hasinstructions": true, @@ -112,6 +114,10 @@ {{error}}