Skip to content

Commit

Permalink
MDL-45113 auth: add is_configured method and convert auth_db to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
mackensen committed Jul 31, 2015
1 parent eb1d954 commit e5ca803
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions auth/db/auth.php
Expand Up @@ -58,6 +58,11 @@ function __construct() {
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);

Expand Down Expand Up @@ -144,8 +149,13 @@ function user_login($username, $password) {
* 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)) {
Expand Down Expand Up @@ -661,6 +671,18 @@ function is_internal() {
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
Expand Down
1 change: 1 addition & 0 deletions lang/en/auth.php
Expand Up @@ -40,6 +40,7 @@
$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?';
Expand Down
9 changes: 9 additions & 0 deletions lib/authlib.php
Expand Up @@ -212,6 +212,15 @@ function is_internal() {
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
Expand Down

0 comments on commit e5ca803

Please sign in to comment.