From 34daec9b3b8a3f4fcfe2db97e4e3b43097be6db5 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 21 Nov 2002 07:37:21 +0000 Subject: [PATCH] Tweaks to authentication system. Database method now allows other fields to be specified so that things like email, names etc can be pulled in from external database when new Moodle accounts are created --- admin/auth.php | 4 +- auth/db/config.html | 106 ++++++++++++++++++++++++++++++++++++++---- auth/db/lib.php | 31 ++++++++++++ auth/imap/config.html | 8 ++-- auth/ldap/config.html | 2 +- auth/nntp/config.html | 6 +-- auth/pop3/config.html | 8 ++-- lang/en/auth.php | 82 ++++++++++++++++---------------- lang/en/moodle.php | 2 + lib/moodlelib.php | 2 +- 10 files changed, 186 insertions(+), 65 deletions(-) diff --git a/admin/auth.php b/admin/auth.php index fcb657c7cd..60458971bc 100644 --- a/admin/auth.php +++ b/admin/auth.php @@ -104,7 +104,9 @@ require("$CFG->dirroot/auth/$auth/config.html"); echo ""; - echo "

guestloginbutton:

"; + echo "

"; + print_string("guestloginbutton", "auth"); + echo ":

"; echo ""; choose_from_menu($guestoptions, "guestloginbutton", $config->guestloginbutton, ""); echo ""; diff --git a/auth/db/config.html b/auth/db/config.html index 493b921e9c..56b53bd1cd 100644 --- a/auth/db/config.html +++ b/auth/db/config.html @@ -1,4 +1,4 @@ - +

auth_dbhost: @@ -9,7 +9,7 @@ - +

auth_dbtype: - +

auth_dbname: @@ -33,7 +33,7 @@ - +

auth_dbuser: @@ -44,7 +44,7 @@ - +

auth_dbpass: @@ -55,7 +55,7 @@ - +

auth_dbtable: @@ -66,7 +66,7 @@ - +

auth_dbfielduser: @@ -77,7 +77,7 @@ - +

auth_dbfieldpass: @@ -88,8 +88,96 @@ + +

: + + + + + + + + + +

: + + + + + + +

: + + + + + + +

1: + + + + + + +

2: + + + + + + +

: + + + + + + +

: + + + + + + +

: + + + + + + +

: + + + + + + +

: + + + + + + +

: + + + + + + +

: + + + + + + -

auth_instructions: +

: diff --git a/auth/db/lib.php b/auth/db/lib.php index 28aeee25bc..45ed5cf0d3 100644 --- a/auth/db/lib.php +++ b/auth/db/lib.php @@ -32,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; +} + ?> diff --git a/auth/imap/config.html b/auth/imap/config.html index 2f0e5c7a00..34b3975cc6 100644 --- a/auth/imap/config.html +++ b/auth/imap/config.html @@ -1,4 +1,4 @@ - +

auth_imaphost: @@ -9,7 +9,7 @@ - +

auth_imaptype: - +

auth_imapport: @@ -33,7 +33,7 @@ -

auth_instructions: +

: diff --git a/auth/ldap/config.html b/auth/ldap/config.html index 6a8a26ffa0..9ca38164f5 100644 --- a/auth/ldap/config.html +++ b/auth/ldap/config.html @@ -63,7 +63,7 @@ -

auth_instructions: +

: diff --git a/auth/nntp/config.html b/auth/nntp/config.html index f9492914c4..5b4375e75b 100644 --- a/auth/nntp/config.html +++ b/auth/nntp/config.html @@ -1,4 +1,4 @@ - +

auth_nntphost: @@ -9,7 +9,7 @@ - +

auth_nntpport: @@ -21,7 +21,7 @@ -

auth_instructions: +

: diff --git a/auth/pop3/config.html b/auth/pop3/config.html index 97fb3d3f84..a219c13e41 100644 --- a/auth/pop3/config.html +++ b/auth/pop3/config.html @@ -1,4 +1,4 @@ - +

auth_pop3host: @@ -9,7 +9,7 @@ - +

auth_pop3type: - +

auth_pop3port: @@ -34,7 +34,7 @@ -

auth_instructions: +

: diff --git a/lang/en/auth.php b/lang/en/auth.php index 1e6c64c5d3..427baf5720 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -1,22 +1,26 @@ -external database fields that you specify here.

If you leave these blank, then defaults will be used.

In either case, the user will be able to edit all of these fields after they log in."; +$string['auth_dbfieldpass'] = "Name of the field containing passwords"; +$string['auth_dbfielduser'] = "Name of the field containing usernames"; +$string['auth_dbhost'] = "The computer hosting the database server."; +$string['auth_dbname'] = "Name of the database itself"; +$string['auth_dbpass'] = "Password matching the above username"; +$string['auth_dbtable'] = "Name of the table in the database"; +$string['auth_dbtitle'] = "Use an external database"; +$string['auth_dbtype'] = "The database type (See the ADOdb documentation for details)"; +$string['auth_dbuser'] = "Username with read access to the database"; $string['auth_emaildescription'] = "Email confirmation is the default authentication method. When the user signs up, choosing their own new username and password, a confirmation email is sent to the user's email address. This email contains a secure link to a page where the user can confirm their account."; - -$string['auth_nonetitle'] = "No authentication"; -$string['auth_nonedescription'] = "Users can sign in and create valid accounts immediately, with no authentication against an external server and no confirmation via email. Be careful using this option - think of the security and administration problems this could cause."; - -$string['auth_ldaptitle'] = "Use an LDAP server"; -$string['auth_ldapdescription'] = "This method provides authentication against an external LDAP server. - If the given username and password are valid, Moodle creates a new user - entry in its database. This module can read user attributes from LDAP and prefill - wanted fields in Moodle. For following logins only the username and - password are checked."; +$string['auth_emailtitle'] = "Email-based authentication"; +$string['auth_imapdescription'] = "This method uses an IMAP server to check whether a given username and password is valid."; +$string['auth_imaphost'] = "The IMAP server address. Use the IP number, not DNS name."; +$string['auth_imapport'] = "IMAP server port number. Usually this is 143 or 993."; +$string['auth_imaptitle'] = "Use an IMAP server"; +$string['auth_imaptype'] = "The IMAP server type. IMAP servers can have different types of authentication and negotiation."; +$string['instructions'] = "Instructions"; $string['auth_ldap_bind_dn'] = "If you want to use bind-user to search users, specify it here. Someting like 'cn=ldapuser,ou=public,o=org'"; $string['auth_ldap_bind_pw'] = "Password for bind-user."; $string['auth_ldap_contexts'] = "List of contexts where users are located. Separate different contexts with ';'. For example: 'ou=users,o=org; ou=others,o=org'"; @@ -24,33 +28,27 @@ $string['auth_ldap_host_url'] = "Specify LDAP host in URL-form like 'ldap://ldap $string['auth_ldap_search_sub'] = "Put value <> 0 if you like to search users from subcontexts."; $string['auth_ldap_update_userinfo'] = "Update user information (firstname, lastname, address..) from LDAP to Moodle. Look at /auth/ldap/attr_mappings.php for mapping information"; $string['auth_ldap_user_attribute'] = "The attribute used to name/search users. Usually 'cn'."; - -$string['auth_imaptitle'] = "Use an IMAP server"; -$string['auth_imapdescription'] = "This method uses an IMAP server to check whether a given username and password is valid."; -$string['auth_imaphost'] = "The IMAP server address. Use the IP number, not DNS name."; -$string['auth_imaptype'] = "The IMAP server type. See the help page (above) for more details."; -$string['auth_imapport'] = "IMAP server port number. Usually this is 143 or 993."; - -$string['auth_dbtitle'] = "Use an external database"; -$string['auth_dbdescription'] = "This method uses an external database table to check whether a given username and password is valid."; -$string['auth_dbhost'] = "The computer hosting the database server."; -$string['auth_dbtype'] = "The database type (See the ADOdb documentation for details)"; -$string['auth_dbname'] = "Name of the database itself"; -$string['auth_dbuser'] = "Username with read access to the database"; -$string['auth_dbpass'] = "Password matching the above username"; -$string['auth_dbtable'] = "Name of the table in the database"; -$string['auth_dbfielduser'] = "Name of the field containing usernames"; -$string['auth_dbfieldpass'] = "Name of the field containing passwords"; - -$string['auth_nntptitle'] = "Use an NNTP server"; +$string['auth_ldapdescription'] = "This method provides authentication against an external LDAP server. + If the given username and password are valid, Moodle creates a new user + entry in its database. This module can read user attributes from LDAP and prefill + wanted fields in Moodle. For following logins only the username and + password are checked."; +$string['auth_ldaptitle'] = "Use an LDAP server"; $string['auth_nntpdescription'] = "This method uses an NNTP server to check whether a given username and password is valid."; -$string['auth_nntphost'] = "The NNTP server address. Use the IP number, not DNS name."; -$string['auth_nntpport'] = "Server port (119 is the most common)"; - -$string['auth_pop3title'] = "Use a POP3 server"; +$string['auth_nntphost'] = "The NNTP server address. Use the IP number, not DNS name."; +$string['auth_nntpport'] = "Server port (119 is the most common)"; +$string['auth_nntptitle'] = "Use an NNTP server"; +$string['auth_nonedescription'] = "Users can sign in and create valid accounts immediately, with no authentication against an external server and no confirmation via email. Be careful using this option - think of the security and administration problems this could cause."; +$string['auth_nonetitle'] = "No authentication"; $string['auth_pop3description'] = "This method uses a POP3 server to check whether a given username and password is valid."; -$string['auth_pop3host'] = "The POP3 server address. Use the IP number, not DNS name."; -$string['auth_pop3type'] = "Server type. If your server uses certificate security, choose pop3cert."; -$string['auth_pop3port'] = "Server port (110 is the most common)"; +$string['auth_pop3host'] = "The POP3 server address. Use the IP number, not DNS name."; +$string['auth_pop3port'] = "Server port (110 is the most common)"; +$string['auth_pop3title'] = "Use a POP3 server"; +$string['auth_pop3type'] = "Server type. If your server uses certificate security, choose pop3cert."; +$string['authenticationoptions'] = "Authentication options"; +$string['authinstructions'] = "Here you can provide instructions for your users, so they know which username and password they should be using. The text you enter here will appear on the login page. If you leave this blank then no instructions will be printed."; +$string['chooseauthmethod'] = "Choose an authentication method: "; +$string['guestloginbutton'] = "Guest login button"; +$string['showguestlogin'] = "You can hide or show the guest login button on the login page."; ?> diff --git a/lang/en/moodle.php b/lang/en/moodle.php index b7f3365187..202a78c48b 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -106,6 +106,7 @@ $string['deletedactivity'] = "Deleted \$a"; $string['deletedcourse'] = "\$a has been completely deleted"; $string['deletednot'] = "Could not delete \$a !"; $string['deletingcourse'] = "Deleting \$a"; +$string['department'] = "Department"; $string['description'] = "Description"; $string['displayingusers'] = "Displaying users \$a->start to \$a->end"; $string['documentation'] = "Moodle Documentation"; @@ -230,6 +231,7 @@ $string['invalidlogin'] = "Invalid login, please try again"; $string['invalidemail'] = "Invalid email address"; $string['langltr'] = "Language direction left-to-right"; $string['langrtl'] = "Language direction right-to-left"; +$string['language'] = "Language"; $string['languagegood'] = "This language pack is up-to-date! :-)"; $string['lastaccess'] = "Last access"; $string['lastedited'] = "Last edited"; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 815cedf54a..2f6b11a8ea 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1403,7 +1403,7 @@ function create_user_record($username, $password) { if ($CFG->auth_update_userinfo and function_exists(auth_get_userinfo)) { if ($newinfo = auth_get_userinfo($username)) { - foreach ($newinfo as $key=>$value){ + foreach ($newinfo as $key => $value){ $newuser->$key = $value; } } -- 2.39.5