diff --git a/auth/db/auth.php b/auth/db/auth.php index faccb6d540b..f54f0b5dc8a 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -58,6 +58,11 @@ class auth_plugin_db extends auth_plugin_base { function user_login($username, $password) { global $CFG, $DB; + if ($this->is_configured() === false) { + debugging(get_string('auth_notconfigured', 'auth', $this->authtype)); + return false; + } + $extusername = core_text::convert($username, 'utf-8', $this->config->extencoding); $extpassword = core_text::convert($password, 'utf-8', $this->config->extencoding); @@ -138,8 +143,13 @@ class auth_plugin_db extends auth_plugin_base { * Connect to external database. * * @return ADOConnection + * @throws moodle_exception */ function db_init() { + if ($this->is_configured() === false) { + throw new moodle_exception('auth_dbcantconnect', 'auth_db'); + } + // Connect to the external database (forcing new connection). $authdb = ADONewConnection($this->config->type); if (!empty($this->config->debugauthdb)) { @@ -643,6 +653,18 @@ class auth_plugin_db extends auth_plugin_base { return ($this->config->passtype === 'internal'); } + /** + * Returns false if this plugin is enabled but not configured. + * + * @return bool + */ + public function is_configured() { + if (!empty($this->config->type)) { + return true; + } + return false; + } + /** * Indicates if moodle should automatically update internal user * records with data from external sources using the information diff --git a/lang/en/auth.php b/lang/en/auth.php index 28f72b3073b..1e2036207d7 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -41,6 +41,7 @@ $string['auth_changingemailaddress'] = 'You have requested a change of email add $string['authinstructions'] = 'Leave this blank for the default login instructions to be displayed on the login page. If you want to provide custom login instructions, enter them here.'; $string['auth_invalidnewemailkey'] = 'Error: if you are trying to confirm a change of email address, you may have made a mistake in copying the URL we sent you by email. Please copy the address and try again.'; $string['auth_multiplehosts'] = 'Multiple hosts OR addresses can be specified (eg host1.com;host2.com;host3.com) or (eg xxx.xxx.xxx.xxx;xxx.xxx.xxx.xxx)'; +$string['auth_notconfigured'] = 'The authentication method {$a} is not configured.'; $string['auth_outofnewemailupdateattempts'] = 'You have run out of allowed attempts to update your email address. Your update request has been cancelled.'; $string['auth_passwordisexpired'] = 'Your password is expired. Do you want change your password now?'; $string['auth_passwordwillexpire'] = 'Your password will expire in {$a} days. Do you want change your password now?'; diff --git a/lib/authlib.php b/lib/authlib.php index dc2ceb90f0c..58369d6422b 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -212,6 +212,15 @@ class auth_plugin_base { return true; } + /** + * Returns false if this plugin is enabled but not configured. + * + * @return bool + */ + public function is_configured() { + return false; + } + /** * Indicates if password hashes should be stored in local moodle database. * @return bool true means md5 password hash stored in user table, false means flag 'not_cached' stored there instead