Skip to content

Commit

Permalink
MDL-72928 core: Remove Remember username
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta authored and Chocolate-lightning committed Feb 11, 2022
1 parent ecb92c7 commit ae14ff3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 38 deletions.
5 changes: 0 additions & 5 deletions auth/classes/output/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -96,10 +94,8 @@ public function __construct(array $authsequence, $username = '') {
$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);
Expand Down Expand Up @@ -156,7 +152,6 @@ public function export_for_template(renderer_base $output) {
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;
Expand Down
13 changes: 0 additions & 13 deletions auth/tests/behat/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion auth/tests/behat/loginform.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 32 additions & 6 deletions auth/tests/behat/rememberusername.feature
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 ""
10 changes: 0 additions & 10 deletions blocks/login/block_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ function get_content () {
$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>';
Expand Down
2 changes: 0 additions & 2 deletions lib/templates/loginform.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": "",
Expand Down
2 changes: 1 addition & 1 deletion login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
// 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('');

Expand Down

0 comments on commit ae14ff3

Please sign in to comment.