MDL-9399 login/index, moodlelib: move session setup logic to complete_user_login()

Move most of the user session setup logic from login/index.php to
complete_user_login().
This commit is contained in:
martinlanghoff
2007-11-14 23:34:29 +00:00
parent 5f3315e78e
commit 9d6a3d1513
2 changed files with 63 additions and 40 deletions
+55
View File
@@ -2921,6 +2921,10 @@ function guest_user() {
*
* Uses auth_ functions from the currently active auth module
*
* After authenticate_user_login() returns success, you will need to
* log that the user has logged in, and call complete_user_login() to set
* the session up.
*
* @uses $CFG
* @param string $username User's username (with system magic quotes)
* @param string $password User's password (with system magic quotes)
@@ -3005,6 +3009,57 @@ function authenticate_user_login($username, $password) {
return false;
}
/**
* Call to complete the user login process after authenticate_user_login()
* has succeeded. It will setup the $USER variable and other required bits
* and pieces.
*
* NOTE:
* - It will NOT log anything -- up to the caller to decide what to log.
*
*
*
* @uses $CFG, $USER
* @param string $user obj
* @return user|flase A {@link $USER} object or false if error
*/
function complete_user_login($user) {
global $CFG, $USER;
$USER = $user; // should not be needed, but cover for legacy code
update_user_login_times();
if (empty($CFG->nolastloggedin)) {
set_moodle_cookie($USER->username);
} else {
// do not store last logged in user in cookie
// auth plugins can temporarily override this from loginpage_hook()
// do not save $CFG->nolastloggedin in database!
set_moodle_cookie('nobody');
}
set_login_session_preferences();
/// This is what lets the user do anything on the site :-)
load_all_capabilities();
/// Select password change url
$userauth = get_auth_plugin($USER->auth);
/// check whether the user should be changing password
if (get_user_preferences('auth_forcepasswordchange', false)){
if ($userauth->can_change_password()) {
if ($changeurl = $userauth->change_password_url()) {
redirect($changeurl);
} else {
redirect($CFG->httpswwwroot.'/login/change_password.php');
}
} else {
error(get_string('nopasswordchangeforced', 'auth'));
}
}
return $USER;
}
/**
* Compare password against hash stored in internal user table.
* If necessary it also updates the stored hash to new format.
+8 -40
View File
@@ -150,47 +150,15 @@ httpsrequired();
die;
}
if ($frm->password == 'changeme') {
//force the change
set_user_preference('auth_forcepasswordchange', true, $user->id);
}
/// Let's get them all set up.
$USER = $user;
add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID, $USER->id, 0, $USER->id);
update_user_login_times();
if (empty($CFG->nolastloggedin)) {
set_moodle_cookie($USER->username);
} else {
// do not store last logged in user in cookie
// auth plugins can temporarily override this from loginpage_hook()
// do not save $CFG->nolastloggedin in database!
set_moodle_cookie('nobody');
}
set_login_session_preferences();
/// This is what lets the user do anything on the site :-)
load_all_capabilities();
/// Select password change url
$userauth = get_auth_plugin($USER->auth);
/// check whether the user should be changing password
if (get_user_preferences('auth_forcepasswordchange', false) || $frm->password == 'changeme'){
if ($frm->password == 'changeme') {
//force the change
set_user_preference('auth_forcepasswordchange', true);
}
//Select password change url
if ($userauth->can_change_password()) {
if ($changeurl = $userauth->change_password_url()) {
redirect($changeurl);
} else {
redirect($CFG->httpswwwroot.'/login/change_password.php');
}
} else {
error(get_string('nopasswordchangeforced', 'auth'));
}
}
add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID,
$user->id, 0, $user->id);
$USER = complete_user_login($user);
/// Prepare redirection
if (user_not_fully_set_up($USER)) {