Tweaks to authentication system. Database method now allows other
[moodle.git] / auth / db / lib.php
index 9f220e7..45ed5cf 100644 (file)
@@ -4,15 +4,6 @@
 // This code is completely untested so far - IT NEEDS TESTERS!
 // Looks like it should work though ...
 
-$CFG->auth_dbhost   = "localhost"; // The computer hosting the database server
-$CFG->auth_dbtype   = "mysql";     // The database type (mysql, postgres7, access, oracle etc)
-$CFG->auth_dbname   = "authtest";  // Name of the database itself
-$CFG->auth_dbuser   = "user";      // Username with read access to the database
-$CFG->auth_dbpass   = "pass";      // Password matching the above username
-$CFG->auth_dbtable  = "users";     // Name of the table in the database
-$CFG->auth_dbfielduser = "user";   // Name of the field containing usernames
-$CFG->auth_dbfieldpass = "pass";   // Name of the field containing passwords
-$CFG->auth_instructions = "Use the same username and password as your school account";   // Instructions
 
 function auth_user_login ($username, $password) {
 // Returns true if the username and password work
@@ -41,4 +32,35 @@ function auth_user_login ($username, $password) {
 }
 
 
+function auth_get_userinfo($username){
+// Reads any other information for a user from external database,
+// then returns it in an array
+
+    global $CFG;
+    $config = (array) $CFG;
+
+    ADOLoadCode($CFG->auth_dbtype);          
+    $authdb = &ADONewConnection();         
+    $authdb->PConnect($CFG->auth_dbhost,$CFG->auth_dbuser,$CFG->auth_dbpass,$CFG->auth_dbname); 
+
+    $fields = array("firstname", "lastname", "email", "phone1", "phone2", 
+                    "department", "address", "city", "country", "description", 
+                    "idnumber", "lang");
+
+    $result = array();
+
+    foreach ($fields as $field) {
+        if ($config["auth_user_$field"]) {
+            if ($rs = $authdb->Execute("SELECT ".$config["auth_user_$field"]." FROM $CFG->auth_dbtable
+                                        WHERE $CFG->auth_dbfielduser = '$username'")) {
+                if ( $rs->RecordCount() == 1 ) {
+                    $result["$field"] = $rs->fields[$config["auth_user_$field"]];
+                }
+            }
+        }
+    }
+
+    return $result;
+}
+
 ?>