Commit 0b78886d authored by Nigel McNie's avatar Nigel McNie

Improve the robustness of authinstance-in-session handling, to handle an...

Improve the robustness of authinstance-in-session handling, to handle an unduplicatable bug (at least by me).

All users who log in to the system should have a valid authinstance in their session. Apparently however, some don't. I can't narrow down how this happens, but this patch will make sure things don't blow up in this case.
parent fcdaef8b
......@@ -365,8 +365,13 @@ function auth_setup () {
if ($sessionlogouttime && isset($_GET['logout'])) {
// Call the authinstance' logout hook
$authinstance = $SESSION->get('authinstance');
$authobj = AuthFactory::create($authinstance);
$authobj->logout();
if ($authinstance) {
$authobj = AuthFactory::create($authinstance);
$authobj->logout();
}
else {
log_debug("Strange: user " . $USER->get('username') . " had no authinstance set in their session");
}
$USER->logout();
$SESSION->add_ok_msg(get_string('loggedoutok'));
......@@ -411,21 +416,26 @@ function auth_setup () {
// The session timed out
$authinstance = $SESSION->get('authinstance');
$authobj = AuthFactory::create($authinstance);
$mnetuser = 0;
if ($SESSION->get('mnetuser') && $authobj->parent) {
// We wish to remember that the user is an MNET user - even though
// they're using the local login form
$mnetuser = $USER->get('id');
}
if ($authinstance) {
$authobj = AuthFactory::create($authinstance);
$mnetuser = 0;
if ($SESSION->get('mnetuser') && $authobj->parent) {
// We wish to remember that the user is an MNET user - even though
// they're using the local login form
$mnetuser = $USER->get('id');
}
$authobj->logout();
$USER->logout();
$authobj->logout();
$USER->logout();
if ($mnetuser != 0) {
$SESSION->set('mnetuser', $mnetuser);
$SESSION->set('authinstance', $authinstance);
if ($mnetuser != 0) {
$SESSION->set('mnetuser', $mnetuser);
$SESSION->set('authinstance', $authinstance);
}
}
else {
log_debug("Strange: user " . $USER->get('username') . " had no authinstance set in their session");
}
if (defined('JSON')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment