diff --git a/public/lang/en/moodle.php b/public/lang/en/moodle.php index a82d3b87fea..418e3778529 100644 --- a/public/lang/en/moodle.php +++ b/public/lang/en/moodle.php @@ -1247,6 +1247,7 @@ $string['loginrequired'] = 'Login required'; $string['logoof'] = 'Logo of {$a}'; $string['logout'] = 'Log out'; $string['logoutconfirm'] = 'Do you really want to log out?'; +$string['logoutconfirmtitle'] = 'Log out?'; $string['logs'] = 'Logs'; $string['logtoomanycourses'] = '[ more ]'; $string['logtoomanyusers'] = '[ more ]'; diff --git a/public/login/index.php b/public/login/index.php index 9474a318c39..3cf67bf82bc 100644 --- a/public/login/index.php +++ b/public/login/index.php @@ -394,8 +394,13 @@ if (isloggedin() and !isguestuser()) { // prevent logging when already logged in, we do not want them to relogin by accident because sesskey would be changed echo $OUTPUT->box_start(); $logout = new single_button(new moodle_url('/login/logout.php', array('sesskey'=>sesskey(),'loginpage'=>1)), get_string('logout'), 'post'); - $continue = new single_button(new moodle_url('/'), get_string('cancel'), 'get'); - echo $OUTPUT->confirm(get_string('alreadyloggedin', 'error', fullname($USER)), $logout, $continue); + $continue = new single_button(new moodle_url('/'), get_string('gobacktosite'), 'get'); + echo $OUTPUT->confirm( + message: get_string('alreadyloggedin', 'error', fullname($USER)), + continue: $logout, + cancel: $continue, + displayoptions: ['confirmtitle' => get_string('logoutconfirmtitle')], + ); echo $OUTPUT->box_end(); } else { $loginform = new \core_auth\output\login($authsequence, $frm->username); diff --git a/public/login/tests/behat/relogin.feature b/public/login/tests/behat/relogin.feature new file mode 100644 index 00000000000..1d2204eb20a --- /dev/null +++ b/public/login/tests/behat/relogin.feature @@ -0,0 +1,21 @@ +@core +Feature: Relogin prevention + User will be informed when trying to login again while already logged in + As a user + I should be informed that I am already logged in + + Background: + Given the following "users" exist: + | username | password | firstname | lastname | email | + | testuser | test | Test | User | user@example.com | + + Scenario: A logged in user tries to access the login page again + Given I follow "Log in" + And I set the field "Username" to "testuser" + And I set the field "Password" to "test" + And I press "Log in" + And I should see "You are logged in as" + When I visit "/login" + Then I should see "You are already logged in as Test User, you need to log out before logging in as different user." in the "Log out?" "dialogue" + And "Go back to site" "button" should exist in the "Log out?" "dialogue" + And "Log out" "button" should exist in the "Log out?" "dialogue"