MDL-72928 core: Remove Remember username

This commit is contained in:
Jun Pataleta 2022-02-09 16:03:32 +08:00 committed by Mathew May
parent ecb92c7ed9
commit ae14ff321b
7 changed files with 33 additions and 38 deletions

View File

@ -64,8 +64,6 @@ class login implements renderable, templatable {
public $instructions;
/** @var moodle_url The form action login URL. */
public $loginurl;
/** @var bool Whether the username should be remembered. */
public $rememberusername;
/** @var moodle_url The sign-up URL. */
public $signupurl;
/** @var string The user name to pre-fill the form with. */
@ -96,10 +94,8 @@ class login implements renderable, templatable {
$this->cansignup = $CFG->registerauth == 'email' || !empty($CFG->registerauth);
if ($CFG->rememberusername == 0) {
$this->cookieshelpicon = new help_icon('cookiesenabledonlysession', 'core');
$this->rememberusername = false;
} else {
$this->cookieshelpicon = new help_icon('cookiesenabled', 'core');
$this->rememberusername = true;
}
$this->autofocusform = !empty($CFG->loginpageautofocus);
@ -156,7 +152,6 @@ class login implements renderable, templatable {
list($data->instructions, $data->instructionsformat) = external_format_text($this->instructions, FORMAT_MOODLE,
context_system::instance()->id);
$data->loginurl = $this->loginurl->out(false);
$data->rememberusername = $this->rememberusername;
$data->signupurl = $this->signupurl->out(false);
$data->username = $this->username;
$data->logintoken = $this->logintoken;

View File

@ -40,19 +40,6 @@ Feature: Authentication
When I click on "Log out" "link" in the "#page-footer" "css_element"
Then I should see "You are not logged in" in the "page-footer" "region"
Scenario Outline: Checking the display of the Remember username checkbox
Given the following config values are set as admin:
| rememberusername | <settingvalue> |
And I am on homepage
When I click on "Log in" "link" in the ".logininfo" "css_element"
Then I should <expect> "Remember username"
Examples:
| settingvalue | expect |
| 0 | not see |
| 1 | see |
| 2 | see |
@javascript @accessibility
Scenario: Login page must be accessible
When I am on site homepage

View File

@ -89,7 +89,6 @@ Feature: Test if the login form provides the correct feedback
Then the focused element is "Username" "field"
And I set the field "Username" to "admin"
And I set the field "Password" to "admin"
And I set the field "Remember username" to "1"
And I press "Log in"
And I log out
And I follow "Log in"

View File

@ -1,8 +1,8 @@
@core @core_auth
Feature: Test the 'remember username' feature works.
In order to see my saved username on the login form
In order for users to easily log in to the site
As a user
I need to have logged in once before and clicked 'Remember username'
I need the site to remember my username when the feature is enabled
Background:
Given the following "users" exist:
@ -11,16 +11,42 @@ Feature: Test the 'remember username' feature works.
# Given the user has logged in and selected 'Remember username', when they log in again, then their username should be remembered.
Scenario: Check that 'remember username' works without javascript for teachers.
# Log in the first time and check the 'remember username' box.
Given I am on homepage
# Log in the first time with $CFG->rememberusername set to Yes.
Given the following config values are set as admin:
| rememberusername | 1 |
And I am on homepage
And I click on "Log in" "link" in the ".logininfo" "css_element"
And I set the field "Username" to "teacher1"
And I set the field "Password" to "teacher1"
And I set the field "Remember username" to "1"
And I press "Log in"
And I log out
# Log out and check that the username was remembered.
When I am on homepage
And I click on "Log in" "link" in the ".logininfo" "css_element"
Then the field "username" matches value "teacher1"
And the field "Remember username" matches value "1"
# Given the user has logged in before and selected 'Remember username', when they log in again and unset 'Remember username', then
# their username should be forgotten for future log in attempts.
Scenario: Check that 'remember username' unsetting works without javascript for teachers.
# Log in the first time with $CFG->rememberusername set to Optional.
Given the following config values are set as admin:
| rememberusername | 2 |
And I am on homepage
And I click on "Log in" "link" in the ".logininfo" "css_element"
And I set the field "Username" to "teacher1"
And I set the field "Password" to "teacher1"
And I press "Log in"
And I log out
# Log in again, the username should have been remembered.
When I am on homepage
And I click on "Log in" "link" in the ".logininfo" "css_element"
Then the field "username" matches value "teacher1"
And I set the field "Password" to "teacher1"
And I press "Log in"
And I log out
And the following config values are set as admin:
| rememberusername | 0 |
# Check username has been forgotten.
And I am on homepage
And I click on "Log in" "link" in the ".logininfo" "css_element"
Then the field "username" matches value ""

View File

@ -77,16 +77,6 @@ class block_login extends block_base {
$this->content->text .= ' class="form-control" value="" autocomplete="current-password"/>';
$this->content->text .= '</div>';
if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) {
$checked = $username ? 'checked="checked"' : '';
$this->content->text .= '<div class="form-check">';
$this->content->text .= '<label class="form-check-label">';
$this->content->text .= '<input type="checkbox" name="rememberusername" id="rememberusername"
class="form-check-input" value="1" '.$checked.'/> ';
$this->content->text .= get_string('rememberusername', 'admin').'</label>';
$this->content->text .= '</div>';
}
$this->content->text .= '<div class="form-group">';
$this->content->text .= '<input type="submit" class="btn btn-primary btn-block" value="'.get_string('login').'" />';
$this->content->text .= '</div>';

View File

@ -33,7 +33,6 @@
* instructions - Instructions,
* instructionsformat - Format of instructions,
* loginurl - Login url,
* rememberusername - Remeber username?,
* signupurl - Signup url,
* errorformatted - Formatted error,
* logourl - Flag, logo url,
@ -83,7 +82,6 @@
"instructions": "For full access to this site, you first need to create an account.",
"instructionsformat": "1",
"loginurl": "http://localhost/stable_master/login/index.php",
"rememberusername": true,
"signupurl": "http://localhost/stable_master/login/signup.php",
"cookieshelpiconformatted": "",
"errorformatted": "",

View File

@ -218,7 +218,7 @@ if ($frm and isset($frm->username)) { // Login WITH
// auth plugins can temporarily override this from loginpage_hook()
// do not save $CFG->nolastloggedin in database!
} else if (empty($CFG->rememberusername) or ($CFG->rememberusername == 2 and empty($frm->rememberusername))) {
} else if (empty($CFG->rememberusername)) {
// no permanent cookies, delete old one if exists
set_moodle_cookie('');