From: moodler Date: Mon, 16 Aug 2004 15:41:57 +0000 (+0000) Subject: Finalise the switchover to using the user->auth field when authenticating. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=39a5a35d6d598d55b56c04f497eb8c38b31ad004;p=moodle.git Finalise the switchover to using the user->auth field when authenticating. Thanks, Howard Miller! --- diff --git a/admin/index.php b/admin/index.php index c93cd14e18..bdfeff73a8 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,9 +1,8 @@ You need to create a config.php.
- See the installation instructions."; + header('Location: ../install.php'); die; } @@ -397,14 +396,12 @@ get_string("adminhelpauthentication")."
"; $userdata .= " ".get_string("edituser")." - ". get_string("adminhelpedituser")."
"; - if (is_internal_auth()) { - $userdata .= " wwwroot/$CFG->admin/user.php?newuser=true\">". - get_string("addnewuser")." - ". - get_string("adminhelpaddnewuser")."
"; - $userdata .= " wwwroot/$CFG->admin/uploaduser.php\">". - get_string("uploadusers")." - ". - get_string("adminhelpuploadusers")."
"; - } + $userdata .= " wwwroot/$CFG->admin/user.php?newuser=true\">". + get_string("addnewuser")." - ". + get_string("adminhelpaddnewuser")."
"; + $userdata .= " wwwroot/$CFG->admin/uploaduser.php\">". + get_string("uploadusers")." - ". + get_string("adminhelpuploadusers")."
"; $userdata .= "
 ".get_string("enrolments")." - ". get_string("adminhelpenrolments")."
"; diff --git a/admin/uploaduser.php b/admin/uploaduser.php index 6af462c342..4575e8e6a5 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -151,6 +151,7 @@ $user->{$name} = addslashes($value); } } + $user->auth = 'manual'; $user->confirmed = 1; $user->timemodified = time(); $linenum++; diff --git a/admin/user.php b/admin/user.php index f86770e46b..8ac5b4d364 100644 --- a/admin/user.php +++ b/admin/user.php @@ -78,6 +78,7 @@ } if ($newuser) { // Create a new user + $user->auth = "manual"; $user->firstname = ""; $user->lastname = ""; $user->username = "changeme"; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 5691e40044..75305f9efd 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 { diff --git a/user/edit.html b/user/edit.html index 09ae1cf7c1..b7f44690b2 100644 --- a/user/edit.html +++ b/user/edit.html @@ -19,7 +19,7 @@ if (isadmin()) { $adminself = (($theadmin->id == $USER->id) and ($USER->id == $user->id)); echo ""; echo "

".get_string("username").":"; - if ($adminself || is_internal_auth() ){ + if ($adminself || is_internal_auth($user->auth) ){ echo "username); echo "\">"; @@ -34,7 +34,7 @@ if (isadmin()) { echo ""; echo ""; - if ($adminself || is_internal_auth() ){ + if ($adminself || is_internal_auth($user->auth) ){ echo ""; echo "

".get_string("newpassword").":"; echo "