]> git.mjollnir.org Git - moodle.git/commitdiff
Finalise the switchover to using the user->auth field when authenticating.
authormoodler <moodler>
Mon, 16 Aug 2004 15:41:57 +0000 (15:41 +0000)
committermoodler <moodler>
Mon, 16 Aug 2004 15:41:57 +0000 (15:41 +0000)
Thanks, Howard Miller!

admin/index.php
admin/uploaduser.php
admin/user.php
lib/moodlelib.php
user/edit.html

index c93cd14e183ed6582226d317ea722a0008172280..bdfeff73a8ab240bbe7a3ecd98ac814fc29e561e 100644 (file)
@@ -1,9 +1,8 @@
 <?PHP // $Id$
 
-/// Check that config.php exists
+/// Check that config.php exists, if not then call the install script
     if (!file_exists("../config.php")) {
-        echo "<H2 align=center>You need to create a config.php.<BR>
-                  See the <A HREF=\"http://moodle.com/doc/?frame=install.html\">installation instructions</A>.</H2>";
+        header('Location: ../install.php');
         die;
     }
 
                  get_string("adminhelpauthentication")."</font><br />";
     $userdata .= "<font size=+1>&nbsp;</font><a href=\"user.php\">".get_string("edituser")."</a> - <font size=1>".
                  get_string("adminhelpedituser")."</font><br />";
-    if (is_internal_auth()) {
-        $userdata .= "<font size=+1>&nbsp;</font><a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".
-                      get_string("addnewuser")."</a> - <font size=1>".
-                      get_string("adminhelpaddnewuser")."</font><br />";
-        $userdata .= "<font size=+1>&nbsp;</font><a href=\"$CFG->wwwroot/$CFG->admin/uploaduser.php\">".
-                      get_string("uploadusers")."</a> - <font size=1>".
-                      get_string("adminhelpuploadusers")."</font><br />";
-    }
+    $userdata .= "<font size=+1>&nbsp;</font><a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".
+                 get_string("addnewuser")."</a> - <font size=1>".
+                 get_string("adminhelpaddnewuser")."</font><br />";
+    $userdata .= "<font size=+1>&nbsp;</font><a href=\"$CFG->wwwroot/$CFG->admin/uploaduser.php\">".
+                 get_string("uploadusers")."</a> - <font size=1>".
+                 get_string("adminhelpuploadusers")."</font><br />";
 
     $userdata .= "<hr><font size=+1>&nbsp;</font><a href=\"enrol.php\">".get_string("enrolments")."</a> - <font size=1>".
                  get_string("adminhelpenrolments")."</font><br />";
index 6af462c342cbcba8664bfc142b385a9dac4122a4..4575e8e6a5fd1e616aa31f5f74be9eca91a8825f 100755 (executable)
                         $user->{$name} = addslashes($value);
                     }
                 }
+                $user->auth = 'manual';
                 $user->confirmed = 1;
                 $user->timemodified = time();
                 $linenum++;
index f86770e46b077d786ebbd9f6f21bd48f9b1d67fc..8ac5b4d364d87af795d0953171da0146188e6f3f 100644 (file)
@@ -78,6 +78,7 @@
     }
 
     if ($newuser) {                 // Create a new user
+        $user->auth      = "manual";
         $user->firstname = "";
         $user->lastname  = "";
         $user->username  = "changeme";
index 5691e40044dadbc3e12c9dff58be75d6f0db5b87..75305f9efd9a66ca7393c990dcf8017a7b1faa48 100644 (file)
@@ -695,12 +695,19 @@ function get_moodle_cookie() {
     }
 }
 
-function is_internal_auth() {
+function is_internal_auth($auth='') {
 /// Returns true if an internal authentication method is being used.
+/// if method not specified then, global default is assumed
 
     global $CFG;
 
-    return ($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual");
+    $method = $CFG->auth;
+
+    if (!empty($auth)) {
+        $method = $auth;
+    }
+
+    return ($method == "email" || $method == "none" || $method == "manual");
 }
 
 function create_user_record($username, $password) {
@@ -757,26 +764,29 @@ function authenticate_user_login($username, $password) {
     $md5password = md5($password);
 
     if (empty($CFG->auth)) {
-        $CFG->auth = "email";    // Default authentication module
+        $CFG->auth = "manual";   // Default authentication module
     }
 
     if ($username == "guest") {
-        $CFG->auth = "none";     // Guest account always internal
+        $CFG->auth = "manual";   // Guest account always internal
     }
 
-    // If this is the admin, then just use internal methods
-    // Doing this first (even though it's less efficient) because
-    // the chosen authentication method might hang and lock the
-    // admin out.
-    if (adminlogin($username, $md5password)) {
-        return get_user_info_from_db("username", $username);
+    // OK, the user is a normal user, so try and authenticate them
+
+    // If the user exists, use their stored authentication method
+    // otherwise just use the set method
+
+    $user = NULL;
+    $auth = $CFG->auth;
+
+    if ($user = get_user_info_from_db("username", $username)) {
+        $auth = $user->auth;
     }
 
-    // OK, the user is a normal user, so try and authenticate them
-    require_once("$CFG->dirroot/auth/$CFG->auth/lib.php");
+    require_once("$CFG->dirroot/auth/$auth/lib.php");
 
     if (auth_user_login($username, $password)) {  // Successful authentication
-        if ($user = get_user_info_from_db("username", $username)) {
+        if ($user) {
             if ($md5password <> $user->password) {   // Update local copy of password for reference
                 set_field("user", "password", $md5password, "username", $username);
             }
@@ -786,23 +796,20 @@ function authenticate_user_login($username, $password) {
 
         if (function_exists('auth_iscreator')) {    // Check if the user is a creator
             if (auth_iscreator($username)) {
-                 if (! record_exists("user_coursecreators", "userid", $user->id)) {
-                      $cdata['userid']=$user->id;
-                      $creator = insert_record("user_coursecreators",$cdata);
-                      if (! $creator) {
-                          error("Cannot add user to course creators.");
-                      }
-                  }
+                if (! record_exists("user_coursecreators", "userid", $user->id)) {
+                    $cdata->userid = $user->id;
+                    if (! insert_record("user_coursecreators", $cdata)) {
+                        error("Cannot add user to course creators.");
+                    }
+                }
             } else {
-                 if ( record_exists("user_coursecreators", "userid", $user->id)) {
-                      $creator = delete_records("user_coursecreators", "userid", $user->id);
-                      if (! $creator) {
-                          error("Cannot remove user from course creators.");
-                      }
-                 }
+                if ( record_exists("user_coursecreators", "userid", $user->id)) {
+                    if (! delete_records("user_coursecreators", "userid", $user->id)) {
+                        error("Cannot remove user from course creators.");
+                    }
+                }
             }
-         }
-
+        }
         return $user;
 
     } else {
index 09ae1cf7c1272e00e3a116a4ad657d2804537f74..b7f44690b24f12496ac9cca3abf9f8b7eee397af 100644 (file)
@@ -19,7 +19,7 @@ if (isadmin()) {
     $adminself = (($theadmin->id == $USER->id) and ($USER->id == $user->id));
     echo "<tr valign=top>";
     echo "<td align=right><p>".get_string("username").":</td>";
-    if ($adminself || is_internal_auth() ){
+    if ($adminself || is_internal_auth($user->auth) ){
         echo "<td><input type=\"text\" name=\"username\" size=20 value=\"";
         p($user->username);
         echo "\">";
@@ -34,7 +34,7 @@ if (isadmin()) {
     echo "</td>";
     echo "</tr>";
 
-    if ($adminself || is_internal_auth() ){
+    if ($adminself || is_internal_auth($user->auth) ){
         echo "<tr valign=top>";
         echo "<td align=right><p>".get_string("newpassword").":</td>";
         echo "<td><input type=\"text\" name=\"newpassword\" size=20 value=\"";