If you leave these fields blank, then nothing will be transferred from LDAP and Moodle defaults will be used instead.
In either case, the user will be able to edit all of these fields after they log in.
'; -$string['auth_ldaptitle'] = 'Use an LDAP server'; +$string['auth_ldaptitle'] = 'LDAP server'; $string['auth_ldapnotinstalled'] = 'Cannot use LDAP authentication. The PHP LDAP module is not installed.'; // Manual plugin $string['auth_manualdescription'] = 'This method removes any way for users to create their own accounts. All accounts must be manually created by the admin user.'; -$string['auth_manualtitle'] = 'Manual accounts only'; +$string['auth_manualtitle'] = 'Manual accounts'; // MNET plugin $string['auth_mnettitle'] = 'Moodle Network authentication'; @@ -214,7 +229,7 @@ $string['auth_multiplehosts'] = 'Multiple hosts OR addresses can be specified (e $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_nntptitle'] = 'Use an NNTP server'; +$string['auth_nntptitle'] = 'NNTP server'; $string['auth_nntpnotinstalled'] = 'Cannot use NNTP authentication. The PHP IMAP module is not installed.'; $string['auth_nntpchangepasswordurl_key'] = 'Password-change URL'; $string['auth_nntpport_key'] = 'Port'; @@ -236,7 +251,7 @@ $string['auth_pop3description'] = 'This method uses a POP3 server to check wheth $string['auth_pop3host'] = 'The POP3 server address. Use the IP number, not DNS name.'; $string['auth_pop3mailbox'] = 'Name of the mailbox to attempt a connection with. (usually INBOX)'; $string['auth_pop3port'] = 'Server port (110 is the most common, 995 is common for SSL)'; -$string['auth_pop3title'] = 'Use a POP3 server'; +$string['auth_pop3title'] = 'POP3 server'; $string['auth_pop3type'] = 'Server type. If your server uses certificate security, choose pop3cert.'; $string['auth_pop3notinstalled'] = 'Cannot use POP3 authentication. The PHP IMAP module is not installed.'; $string['auth_pop3changepasswordurl_key'] = 'Password-change URL'; @@ -246,7 +261,7 @@ $string['auth_pop3type_key'] = 'Type'; $string['auth_pop3host_key'] = 'Host'; // RADIUS plugin -$string['auth_radiustitle'] = 'Use a RADIUS server'; +$string['auth_radiustitle'] = 'RADIUS server'; $string['auth_radiusdescription'] = 'This method uses a RADIUS server to check whether a given username and password is valid.'; $string['auth_radiushost'] = 'Address of the RADIUS server'; $string['auth_radiusnasport'] = 'Port to use to connect'; @@ -301,7 +316,7 @@ $string['passwordhandling'] = 'Password field handling'; $string['plaintext'] = 'Plain text'; $string['selfregistration'] = 'Self registration'; $string['selfregistration_help'] = 'Choose which auth plugin will handle user self-registration.'; -$string['sha1'] = 'SHA1 hash'; +$string['sha1'] = 'SHA-1 hash'; $string['showguestlogin'] = 'You can hide or show the guest login button on the login page.'; $string['stdchangepassword'] = 'Use standard Change Password Page'; $string['stdchangepassword_expl'] = 'If the external authentication system allows password changes through Moodle, switch this to Yes. This setting overrides \'Change Password URL\'.'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index dbf48477422..639078d72da 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -138,6 +138,9 @@ function xmldb_main_upgrade($oldversion=0) { if (strpos($k, 'auth_') !== 0) { continue; } + if ($k == 'auth_instructions') { + continue; //keep as global auth option + } $authsetting = substr($k, 5); foreach ($authplugins as $auth) { if (strpos($authsetting, $auth) !== 0) { diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 345b476a907..8cc20ee392e 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2323,13 +2323,9 @@ function get_moodle_cookie() { * global setting in {@link $CFG}. * @return boolean Whether the plugin is available. */ -function exists_auth_plugin($auth='') { +function exists_auth_plugin($auth) { global $CFG; - // use the global default if not specified - if ($auth == '') { - $auth = $CFG->auth; - } if (file_exists("{$CFG->dirroot}/auth/$auth/auth.php")) { return is_readable("{$CFG->dirroot}/auth/$auth/auth.php"); } @@ -2342,14 +2338,16 @@ function exists_auth_plugin($auth='') { * @param string $auth Authentication plugin. * @return boolean Whether the plugin is enabled. */ -function is_enabled_auth($auth='') { +function is_enabled_auth($auth) { global $CFG; - // use the global default if not specified - if ($auth == '') { - $auth = $CFG->auth; + if (empty($auth)) { + return false; + } else if ($auth == 'manual') { + return true; } - return in_array($auth, explode(',', $CFG->auth_plugins_enabled)); + + return in_array($auth, explode(',', $CFG->auth)); } /** @@ -2363,12 +2361,10 @@ function is_enabled_auth($auth='') { function get_auth_plugin($auth = '') { global $CFG; - // use the global default if not specified - if ($auth == '') { - $auth = $CFG->auth; + // use the manual if not specified + if (empty($auth)) { + $auth = 'manual'; } - - // TODO: plugin enabled? // check the plugin exists first if (! exists_auth_plugin($auth)) { @@ -2390,7 +2386,7 @@ function get_auth_plugin($auth = '') { * @return bool * @todo Outline auth types and provide code example */ -function is_internal_auth($auth='') { +function is_internal_auth($auth) { $authplugin = get_auth_plugin($auth); // throws error if bad $auth return $authplugin->is_internal(); } @@ -2434,7 +2430,7 @@ function create_user_record($username, $password, $auth='') { if ($newinfo = $authplugin->get_userinfo($username)) { $newinfo = truncate_userinfo($newinfo); foreach ($newinfo as $key => $value){ - $newuser->$key = addslashes(stripslashes($value)); // Just in case + $newuser->$key = addslashes($value); } } } @@ -2445,9 +2441,8 @@ function create_user_record($username, $password, $auth='') { } } - $newuser->auth = (empty($auth)) ? $CFG->auth : $auth; + $newuser->auth = (empty($auth)) ? 'manual' : $auth; $newuser->username = $username; - update_internal_user_password($newuser, $password, false); // fix for MDL-8480 // user CFG lang for user if $newuser->lang is empty @@ -2462,11 +2457,12 @@ function create_user_record($username, $password, $auth='') { $newuser->mnethostid = $CFG->mnet_localhost_id; if (insert_record('user', $newuser)) { - $user = get_complete_user_data('username', $newuser->username); - if($CFG->{'auth_'.$newuser->auth.'_forcechangepassword'}){ - set_user_preference('auth_forcepasswordchange', 1, $user->id); - } - return $user; + $user = get_complete_user_data('username', $newuser->username); + if($CFG->{'auth_'.$newuser->auth.'_forcechangepassword'}){ + set_user_preference('auth_forcepasswordchange', 1, $user->id); + } + update_internal_user_password($user, $password); + return $user; } return false; } @@ -2567,45 +2563,37 @@ function authenticate_user_login($username, $password) { global $CFG; - // default to manual if global auth is undefined or broken - if (empty($CFG->auth_plugins_enabled)) { - $CFG->auth_plugins_enabled = empty($CFG->auth) ? 'manual' : $CFG->auth; - } - // if blank, set default auth to first enabled auth plugin if (empty($CFG->auth)) { - $auths = explode(',', $CFG->auth_plugins_enabled); - $CFG->auth = $auths[0]; - } - - // if user not found, use site auth - if (!$user = get_complete_user_data('username', $username)) { - $user = new object(); - $user->id = 0; // Not a user - $auth = $CFG->auth_plugins_enabled; - } - - // Sort out the authentication method we are using. - if (empty($user->auth)) { // For some reason it isn't set yet - $primadmin = get_admin(); - if (!empty($user->id) && (($user->id==$primadmin->id) || isguest($user->id))) { - $auth = 'manual'; // always assume these guys are internal - } - else { - $auth = $CFG->auth_plugins_enabled; // default to site method - } + $authsenabled = array('manual'); } else { - $auth = $user->auth; + $authsenabled = explode(',', 'manual,'.$CFG->auth); + } + + if ($user = get_complete_user_data('username', $username)) { + $auth = empty($user->auth) ? 'manual' : $user->auth; // use manual if auth not set + if ($auth=='nologin' or !is_enabled_auth($auth)) { + add_to_log(0, 'login', 'error', 'index.php', $username); + error_log('[client '.$_SERVER['REMOTE_ADDR']."] $CFG->wwwroot Disabled Login: $username ".$_SERVER['HTTP_USER_AGENT']); + return false; + } + if (!empty($user->deleted)) { + add_to_log(0, 'login', 'error', 'index.php', $username); + error_log('[client '.$_SERVER['REMOTE_ADDR']."] $CFG->wwwroot Deleted Login: $username ".$_SERVER['HTTP_USER_AGENT']); + return false; + } + $auths = array($auth); + + } else { + $auths = $authsenabled; + $user = new object(); + $user->id = 0; // User does not exist } - // walk each authentication plugin, in order - $auths = explode(',', $auth); foreach ($auths as $auth) { $authplugin = get_auth_plugin($auth); - // on auth fail, log and fall through to the next plugin + // on auth fail fall through to the next plugin if (!$authplugin->user_login($username, $password)) { - add_to_log(0, 'login', 'error', 'index.php', $username); - error_log("[client {$_SERVER['REMOTE_ADDR']}] $CFG->wwwroot Auth=$auth Failed Login: $username {$_SERVER['HTTP_USER_AGENT']}"); continue; } @@ -2613,12 +2601,16 @@ function authenticate_user_login($username, $password) { if ($user->id) { // User already exists in database if (empty($user->auth)) { // For some reason auth isn't set yet set_field('user', 'auth', $auth, 'username', $username); + $user->auth = $auth; } - update_internal_user_password($user, $password); + + update_internal_user_password($user, $password); // just in case salt or encoding were changed (magic quotes too one day) + if (!$authplugin->is_internal()) { // update user record from external DB $user = update_user_record($username, get_auth_plugin($user->auth)); } } else { + // if user not found, create him $user = create_user_record($username, $password, $auth); } // fix for MDL-6928 @@ -2723,11 +2715,11 @@ function hash_internal_user_password($password) { * @param bool store changes also in db, default true * @return true if hash changed */ -function update_internal_user_password(&$user, $password, $storeindb=true) { +function update_internal_user_password(&$user, $password) { global $CFG; $authplugin = get_auth_plugin($user->auth); - if (!empty($authplugin->config->preventpassindb) /*|| $storeindb === false */) { + if (!empty($authplugin->config->preventpassindb)) { $hashedpassword = 'not cached'; } else { $hashedpassword = hash_internal_user_password($password); @@ -3258,6 +3250,11 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a return false; } + // skip mail to suspended users + if ($user->auth=='nologin') { + return true; + } + if (!empty($user->emailstop)) { return 'emailstop'; }