]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9053 - adding new function get_enabled_auth_plugins() - this should make the...
authorskodak <skodak>
Tue, 27 Mar 2007 20:26:05 +0000 (20:26 +0000)
committerskodak <skodak>
Tue, 27 Mar 2007 20:26:05 +0000 (20:26 +0000)
admin/auth.php
admin/cron.php
lib/moodlelib.php
login/index.php
login/logout.php

index ff57cf87c640ef33477eb69aedccad2302a2307b..d6ab820a1ac48aaa55ee7e11f1bad184732192d0 100644 (file)
@@ -27,17 +27,11 @@ if (isset($CFG->auth_plugins_enabled)) {
     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)) {
index 334c6069c7e821cce70b7a99664dd2df1ebf6085..dbc2a3027ba38893c7edf87a32849cc1dba3bf93 100644 (file)
     }
 
 /// 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);
index d7c1f0884a68897a6f9d53db142b85243e60c436..c399bb0df25dcc8b07c1242995937614b6f166b0 100644 (file)
@@ -1829,7 +1829,7 @@ function require_logout() {
         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');
@@ -2376,15 +2376,13 @@ function exists_auth_plugin($auth) {
  * @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);
 }
 
 /**
@@ -2408,6 +2406,39 @@ function get_auth_plugin($auth) {
     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
@@ -2590,11 +2621,7 @@ function authenticate_user_login($username, $password) {
 
     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
index f1151ca17c82584094cf6ac6107ce1a3df4beb25..317be9b830f8c775ffc460b173fc8e49da97e308 100644 (file)
         }
     }
 
-/// 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', '');
@@ -54,29 +51,12 @@ if (!isset($CFG->auth_instructions)) {
     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();
 }
index 4b7abf69d518f3f42536fee3e014d9d4242b8fee..2883a333787a672182132e76ae34ea4b0f96a650 100644 (file)
@@ -15,7 +15,7 @@
         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();