Moodle

Prefill username on login page when passed via GET

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.4
  • Fix Version/s: 1.9.5
  • Component/s: Authentication
  • Labels:
    None
  • Database:
    Any
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

Currently, when Moodle's login page is accessed as an unauthenticated user, the "username" input field gets automatically prefilled if a proper MOODLEID_ cookie exists.

I wrote a little patch that improves the auto-username-prefilling ability: If the username is passed to the login script as a GET variable, it gets auto-filled in, too. This makes it convenient to link from other systems sharing the same usernames to Moodle's login page if the user is already logged in in the other system, but not yet into Moodle. Then links of the form

/moodle/login/index.php?username=john

can be used and the user usually just have to click the Login button to login to Moodle.

Activity

Hide
Robert Allerstorfer added a comment -

The attached patch against MOODLE_19_STABLE would implement this. It would be great to get it committed into 1.9, since it does not change the current behaviour in any way, just offers an improvement for those developers who are aware of it. I am using it as a simple solution for a "quasi-SSO" from Drupal (6.9) to Moodle (1.9.4+).

Show
Robert Allerstorfer added a comment - The attached patch against MOODLE_19_STABLE would implement this. It would be great to get it committed into 1.9, since it does not change the current behaviour in any way, just offers an improvement for those developers who are aware of it. I am using it as a simple solution for a "quasi-SSO" from Drupal (6.9) to Moodle (1.9.4+).
Hide
Robert Allerstorfer added a comment -

Added Iñaki to the watch list, since the latest modification of login/index.php in CVS was made by him. Could you please comment my proposal, Iñaki?

Show
Robert Allerstorfer added a comment - Added Iñaki to the watch list, since the latest modification of login/index.php in CVS was made by him. Could you please comment my proposal, Iñaki?
Hide
Petr Škoda (skodak) added a comment -

next time please turn on debug mode

committed into cvs, thanks

Show
Petr Škoda (skodak) added a comment - next time please turn on debug mode committed into cvs, thanks
Hide
Robert Allerstorfer added a comment -

Thank you very much Petr for committing it, and sorry for the dirty variable check

BTW, did you recognize the unnecessary double call of get_moodle_cookie() in
$frm->username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie();

Changing that line to

$frm->username = get_moodle_cookie();
if ($frm->username === 'nobody') {
$frm->username = '';
}

would execute faster.

Show
Robert Allerstorfer added a comment - Thank you very much Petr for committing it, and sorry for the dirty variable check BTW, did you recognize the unnecessary double call of get_moodle_cookie() in $frm->username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie(); Changing that line to $frm->username = get_moodle_cookie(); if ($frm->username === 'nobody') { $frm->username = ''; } would execute faster.
Hide
Robert Allerstorfer added a comment -

Works perfectly - thus closing.

Show
Robert Allerstorfer added a comment - Works perfectly - thus closing.
Hide
Petr Škoda (skodak) added a comment -

Did you recognise that we are not setting cookie with 'guest' all?
Any way I am planning some 2.0 cleanup in this are, going fix some other things there too.

Show
Petr Škoda (skodak) added a comment - Did you recognise that we are not setting cookie with 'guest' all? Any way I am planning some 2.0 cleanup in this are, going fix some other things there too.
Hide
Robert Allerstorfer added a comment -

You don't need to login as guest to be affected of the delayed login time. When you are logged into Moodle and log out, your username is still stored (encrypted) in the MOODLEID_ cookie. When you want to login again, the (not so small) get_moodle_cookie() function will be executed two times: first, to know that it does not return 'nobody'. Then, again to actually save the returned username.

Show
Robert Allerstorfer added a comment - You don't need to login as guest to be affected of the delayed login time. When you are logged into Moodle and log out, your username is still stored (encrypted) in the MOODLEID_ cookie. When you want to login again, the (not so small) get_moodle_cookie() function will be executed two times: first, to know that it does not return 'nobody'. Then, again to actually save the returned username.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: