From 565809c603bf3f387bea3892844c5360e4b2d0b1 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 17 Apr 2005 13:06:25 +0000 Subject: [PATCH] Moved login.php to index.php in shibboleth --- auth/shibboleth/README.txt | 2 +- auth/shibboleth/index.php | 65 ++++++++++++++++++++++++++++++++++++++ auth/shibboleth/lib.php | 2 +- login/index.php | 2 +- 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 auth/shibboleth/index.php diff --git a/auth/shibboleth/README.txt b/auth/shibboleth/README.txt index eabe647fff8..29f69de3e26 100644 --- a/auth/shibboleth/README.txt +++ b/auth/shibboleth/README.txt @@ -32,7 +32,7 @@ Moodle Configuration How the Shibboleth authentication works -------------------------------------------------------------------------------- For a user to get Shibboleth authenticated in Moodle he first must get -redirected to moodle/auth/shibboleth/login.php . When Shibboleth is active +redirected to moodle/auth/shibboleth/index.php . When Shibboleth is active this happens automatically from the normal login page. If the user is successfully Shibboleth authenticated he also is authenticated in Moodle diff --git a/auth/shibboleth/index.php b/auth/shibboleth/index.php new file mode 100644 index 00000000000..4cf7348bb30 --- /dev/null +++ b/auth/shibboleth/index.php @@ -0,0 +1,65 @@ +wwwroot.'/index.php'); + } + +/// If shibboleth login is enforced, directly go to the authentication page + + if ($CFG->auth == 'shibboleth' and !empty($CFG->auth_shib_only)) { + if (empty($CFG->shib_user_attribute)) { + error('Shibboleth authentication (shib_user_attribute) is not set up correctly'); + } + if (empty($_SERVER[$CFG->shib_user_attribute])) { + error('Shibboleth authentication is not set up correctly (could not find $_SERVER[\''.$CFG->shib_user_attribute.'\'])'); + } + } + +/// If we can find some Shibboleth information, save it in session and return to main login page + + if (!empty($_SERVER[$CFG->shib_user_attribute])) { // Shibboleth auto-login + $frm->username = $_SERVER[$CFG->shib_user_attribute]; + $frm->password = substr(base64_encode($_SERVER[$CFG->shib_user_attribute]),0,8); + // The random password consists of the first 8 letters of the base 64 encoded user ID + // This password is never used unless the user account is converted to manual + + + /// Check if the user has actually submitted login data to us + + if ($user = authenticate_user_login($frm->username, $frm->password)) { + + // 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(); + set_moodle_cookie($USER->username); + set_login_session_preferences(); + + if (user_not_fully_set_up($USER)) { + $urltogo = $CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&course='.SITEID; + // We don't delete $SESSION->wantsurl yet, so we get there later + + } else if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) { + $urltogo = $SESSION->wantsurl; /// Because it's an address in this site + unset($SESSION->wantsurl); + + } else { + $urltogo = $CFG->wwwroot.'/'; /// Go to the standard home page + unset($SESSION->wantsurl); /// Just in case + } + + redirect($urltogo); + } + } + + $SESSION->shibboleth_checked = true; // This will stop us bouncing back here + + redirect($CFG->wwwroot.'/login/index.php'); + +?> diff --git a/auth/shibboleth/lib.php b/auth/shibboleth/lib.php index 5f3cd399b4b..d41afb71030 100755 --- a/auth/shibboleth/lib.php +++ b/auth/shibboleth/lib.php @@ -14,7 +14,7 @@ function auth_user_login ($username, $password) { /// If we are not, then the server is probably set to not be Shibboleth-only /// and the user has used the normal login screen, so we redirect to the shibboleth /// directory for a proper check - redirect($CFG->wwwroot.'/auth/shibboleth/login.php'; + redirect($CFG->wwwroot.'/auth/shibboleth/index.php'; /// There's no point doing anything further here exit; diff --git a/login/index.php b/login/index.php index b083308d992..2cb7d5b7ee8 100644 --- a/login/index.php +++ b/login/index.php @@ -32,7 +32,7 @@ if (!empty($SESSION->shibboleth_checked)) { // Just come from there unset($SESSION->shibboleth_checked); } else { - redirect($CFG->wwwroot.'/auth/shibboleth/login.php'); + redirect($CFG->wwwroot.'/auth/shibboleth/index.php'); } }