unset($CFG->auth_plugins_enabled);
}
+get_enabled_auth_plugins(true); // fix the list of enabled auths
if (empty($CFG->auth)) {
$authsenabled = array();
} else {
$authsenabled = explode(',', $CFG->auth);
- $authsenabled = array_unique($authsenabled);
-}
-
-$key = array_search('manual', $authsenabled);
-if ($key !== false) {
- unset($authsenabled[$key]); // manual is always enabled anyway
- set_config('auth', implode(',', $authsenabled));
}
if (!isset($CFG->registerauth)) {
}
/// Run the auth cron, if any
- if (empty($CFG->auth)) {
- $auths = array();
- } else {
- $auths = explode(',', $CFG->auth); // only for enabled ones (without manual and nologin)
- }
+ $auths = get_enabled_auth_plugins();
+
mtrace("Running auth crons if required...");
foreach ($auths as $auth) {
$authplugin = get_auth_plugin($auth);
add_to_log(SITEID, "user", "logout", "view.php?id=$USER->id&course=".SITEID, $USER->id, 0, $USER->id);
//TODO: move following 2 ifs into auth plugins - add new logout hook
- $authsequence = explode(',', $CFG->auth);
+ $authsequence = get_enabled_auth_plugins();
if (in_array('cas', $authsequence) and $USER->auth == 'cas' and !empty($CFG->cas_enabled)) {
require($CFG->dirroot.'/auth/cas/logout.php');
* @return boolean Whether the plugin is enabled.
*/
function is_enabled_auth($auth) {
- global $CFG;
-
if (empty($auth)) {
return false;
- } else if ($auth == 'manual') {
- return true;
}
- return in_array($auth, explode(',', $CFG->auth));
+ $enabled = get_enabled_auth_plugins();
+
+ return in_array($auth, $enabled);
}
/**
return new $class;
}
+/**
+ * Returns array of active auth plugins.
+ *
+ * @param bool $fix fix $CFG->auth if needed
+ * @return array
+ */
+function get_enabled_auth_plugins($fix=false) {
+ global $CFG;
+
+ $default = array('manual', 'nologin');
+
+ if (empty($CFG->auth)) {
+ $auths = array();
+ } else {
+ $auths = explode(',', $CFG->auth);
+ }
+
+ if ($fix) {
+ $auths = array_unique($auths);
+ foreach($auths as $k=>$authname) {
+ if (!exists_auth_plugin($authname) or in_array($authname, $default)) {
+ unset($auths[$k]);
+ }
+ }
+ $newconfig = implode(',', $auths);
+ if (!isset($CFG->auth) or $newconfig != $CFG->auth) {
+ set_config('auth', $newconfig);
+ }
+ }
+
+ return (array_merge($default, $auths));
+}
+
/**
* Returns true if an internal authentication method is being used.
* if method not specified then, global default is assumed
global $CFG;
- if (empty($CFG->auth)) {
- $authsenabled = array('manual');
- } else {
- $authsenabled = explode(',', 'manual,'.$CFG->auth);
- }
+ $authsenabled = get_enabled_auth_plugins();
if ($user = get_complete_user_data('username', $username)) {
$auth = empty($user->auth) ? 'manual' : $user->auth; // use manual if auth not set
}
}
-/// Load alternative login screens if necessary
-
-
-$cfgauthsequence = explode(',', $CFG->auth); // auths, in sequence
+// setup and verify auth settings
if (!isset($CFG->registerauth)) {
set_config('registerauth', '');
set_config('auth_instructions', '');
}
-
-$authsequence = array();
-$fixauthseq = false;
-
-// fix auth sequence if needed to prevent fatal errors during login
-foreach($cfgauthsequence as $authname) {
- if (exists_auth_plugin($authname)) {
- $authsequence[] = $authname;
- continue;
- } else {
- $fixauthseq = true;
- }
-}
-if ($fixauthseq) {
- set_config('auth', implode(',', $authsequence));
-}
-
// auth plugins may override these - SSO anyone?
$frm = false;
$user = false;
+$authsequence = get_enabled_auth_plugins(true); // auths, in sequence
foreach($authsequence as $authname) {
- // manual and nologin is not processed here
$authplugin = get_auth_plugin($authname);
$authplugin->prelogin_hook();
}
die;
}
- $authsequence = explode(',', $CFG->auth); // auths, in sequence
+ $authsequence = get_enabled_auth_plugins(); // auths, in sequence
foreach($authsequence as $authname) {
$authplugin = get_auth_plugin($authname);
$authplugin->prelogout_hook();