]> git.mjollnir.org Git - moodle.git/commitdiff
Merged authentication logic fixes from STABLE
authormoodler <moodler>
Sun, 29 Aug 2004 05:48:15 +0000 (05:48 +0000)
committermoodler <moodler>
Sun, 29 Aug 2004 05:48:15 +0000 (05:48 +0000)
lib/moodlelib.php

index bcab55334fb0082fce3f7bb4cdb7fadcb9d6b8bd..78865a8eb53ff557da2b3c73c59d667ae4556fc8 100644 (file)
@@ -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) {