From: moodler Date: Sun, 29 Aug 2004 05:48:15 +0000 (+0000) Subject: Merged authentication logic fixes from STABLE X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=27286aeb120314aac1a81fd4e92abc479361eeaf;p=moodle.git Merged authentication logic fixes from STABLE --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index bcab55334f..78865a8eb5 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -776,28 +776,29 @@ function authenticate_user_login($username, $password) { $md5password = md5($password); - if (empty($CFG->auth)) { - $CFG->auth = "manual"; // Default authentication module - } - - if ($username == "guest") { - $CFG->auth = "manual"; // Guest account always internal - } + // First try to find the user in the database - // OK, the user is a normal user, so try and authenticate them + $user = get_user_info_from_db("username", $username); - // If the user exists, use their stored authentication method - // otherwise just use the set method + // Sort out the authentication method we are using. - $user = NULL; - $auth = $CFG->auth; + if (empty($CFG->auth)) { + $CFG->auth = "manual"; // Default authentication module + } - $user = get_user_info_from_db("username", $username); - if (!empty($user->auth)) { - $auth = $user->auth; + if (empty($user->auth)) { // For some reason it isn't set yet + if (isadmin($user->id) or isguest($user->id)) { + $user->auth = 'manual'; // Always assume these guys are internal + } else { + $user->auth = $CFG->auth; // Normal users default to site method + } + } + + if (!file_exists("$CFG->dirroot/auth/$user->auth/lib.php")) { + $user->auth = "manual"; // Can't find auth module, default to internal } - require_once("$CFG->dirroot/auth/$auth/lib.php"); + require_once("$CFG->dirroot/auth/$user->auth/lib.php"); if (auth_user_login($username, $password)) { // Successful authentication if ($user) {