MDL-45113 auth: add is_configured method and convert auth_db to use it

This commit is contained in:
Charles Fulton 2015-07-04 19:02:32 +00:00
parent 032a4fe51c
commit b6f28375b7
3 changed files with 32 additions and 0 deletions

View File

@ -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);
@ -144,8 +149,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)) {
@ -661,6 +671,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

View File

@ -40,6 +40,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?';

View File

@ -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