From: moodler Date: Tue, 31 Aug 2004 12:33:20 +0000 (+0000) Subject: Merged changes from stable (fixed external auth) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=71f9abf917448bc603ccc19b49c5205cf8ace513;p=moodle.git Merged changes from stable (fixed external auth) --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 44b1ccb3dc..2345deaa7d 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -533,7 +533,13 @@ function isteacher($courseid=0, $userid=0, $includeadmin=true) { } if (!$userid) { - return !empty($USER->teacher[$courseid]); + if ($courseid) { + return !empty($USER->teacher[$courseid]); + } + if (!isset($USER->id)) { + return false; + } + $userid = $USER->id; } if (!$courseid) { @@ -577,7 +583,7 @@ function iscreator ($userid=0) { function isstudent($courseid, $userid=0) { /// Is the user a student in this course? /// If course is site, is the user a confirmed user on the site? - global $USER; + global $USER, $CFG; if (empty($USER->id) and !$userid) { return false; @@ -590,12 +596,15 @@ function isstudent($courseid, $userid=0) { if (isguest($userid)) { return false; } + // a site teacher can never be a site student + if (isteacher($courseid, $userid)) { + return false; + } if ($CFG->allusersaresitestudents) { return record_exists('user', 'id', $userid); } else { return (record_exists('user_students', 'userid', $userid) - or (record_exists('user_teachers', 'userid', $userid) - and !record_exists('user_teachers', 'userid', $userid, 'course', SITEID))); + or record_exists('user_teachers', 'userid', $userid)); } } @@ -723,11 +732,13 @@ function is_internal_auth($auth='') { return ($method == "email" || $method == "none" || $method == "manual"); } -function create_user_record($username, $password) { +function create_user_record($username, $password, $auth='') { /// Creates a bare-bones user record global $REMOTE_ADDR, $CFG; + //just in case check text case $username = trim(moodle_strtolower($username)); + if (function_exists('auth_get_userinfo')) { if ($newinfo = auth_get_userinfo($username)) { foreach ($newinfo as $key => $value){ @@ -736,7 +747,7 @@ function create_user_record($username, $password) { } } - $newuser->auth = $CFG->auth; + $newuser->auth = (empty($auth)) ? $CFG->auth : $auth; $newuser->username = $username; $newuser->password = md5($password); $newuser->lang = $CFG->lang; @@ -788,25 +799,30 @@ function authenticate_user_login($username, $password) { 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 + $auth = 'manual'; // Always assume these guys are internal } else { - $user->auth = $CFG->auth; // Normal users default to site method + $auth = $CFG->auth; // Normal users default to site method } + } else { + $auth = $user->auth; } - if (!file_exists("$CFG->dirroot/auth/$user->auth/lib.php")) { - $user->auth = "manual"; // Can't find auth module, default to internal + if (!file_exists("$CFG->dirroot/auth/$auth/lib.php")) { + $auth = "manual"; // Can't find auth module, default to internal } - require_once("$CFG->dirroot/auth/$user->auth/lib.php"); + require_once("$CFG->dirroot/auth/$auth/lib.php"); if (auth_user_login($username, $password)) { // Successful authentication - if ($user) { + if ($user) { // User already exists in database + if (empty($user->auth)) { // For some reason auth isn't set yet + set_field('user', 'auth', $auth, 'username', $username); + } if ($md5password <> $user->password) { // Update local copy of password for reference - set_field("user", "password", $md5password, "username", $username); + set_field('user', 'password', $md5password, 'username', $username); } } else { - $user = create_user_record($username, $password); + $user = create_user_record($username, $password, $auth); } if (function_exists('auth_iscreator')) { // Check if the user is a creator