From 9b29f68648acb3066c4cd23d059ba22a0cd181c7 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 11 Feb 2013 11:24:43 +0800 Subject: [PATCH] MDL-27953 auth: introduced new function can_be_manually_set() to the authentication base class --- admin/tool/uploaduser/locallib.php | 7 ++++--- auth/email/auth.php | 9 +++++++++ auth/ldap/auth.php | 9 +++++++++ auth/manual/auth.php | 9 +++++++++ auth/nologin/auth.php | 8 ++++++++ auth/none/auth.php | 9 +++++++++ lib/authlib.php | 17 +++++++++++++++-- 7 files changed, 63 insertions(+), 5 deletions(-) diff --git a/admin/tool/uploaduser/locallib.php b/admin/tool/uploaduser/locallib.php index 928b13e1581..a050e803c61 100644 --- a/admin/tool/uploaduser/locallib.php +++ b/admin/tool/uploaduser/locallib.php @@ -321,12 +321,13 @@ function uu_process_template_callback($username, $firstname, $lastname, $block) * @return array type=>name */ function uu_supported_auths() { - // only following plugins are guaranteed to work properly - $whitelist = array('manual', 'nologin', 'none', 'email'); + // Get all the enabled plugins. $plugins = get_enabled_auth_plugins(); $choices = array(); foreach ($plugins as $plugin) { - if (!in_array($plugin, $whitelist)) { + $objplugin = get_auth_plugin($plugin); + // If the plugin can not be manually set skip it. + if (!$objplugin->can_be_manually_set()) { continue; } $choices[$plugin] = get_string('pluginname', "auth_{$plugin}"); diff --git a/auth/email/auth.php b/auth/email/auth.php index 9ac59bdaa58..e4590048a4d 100644 --- a/auth/email/auth.php +++ b/auth/email/auth.php @@ -195,6 +195,15 @@ class auth_plugin_email extends auth_plugin_base { return true; } + /** + * Returns true if plugin can be manually set. + * + * @return bool + */ + function can_be_manually_set() { + return true; + } + /** * Prints a form for configuring this authentication plugin. * diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index e9d82b72fe5..dae99230a66 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -509,6 +509,15 @@ class auth_plugin_ldap extends auth_plugin_base { return !empty($this->config->stdchangepassword); } + /** + * Returns true if plugin can be manually set. + * + * @return bool + */ + function can_be_manually_set() { + return true; + } + /** * Returns true if plugin allows signup and user creation. * diff --git a/auth/manual/auth.php b/auth/manual/auth.php index 3b4fdae5715..1c7ff9eaa9f 100644 --- a/auth/manual/auth.php +++ b/auth/manual/auth.php @@ -129,6 +129,15 @@ class auth_plugin_manual extends auth_plugin_base { return true; } + /** + * Returns true if plugin can be manually set. + * + * @return bool + */ + function can_be_manually_set() { + return true; + } + /** * Prints a form for configuring this authentication plugin. * diff --git a/auth/nologin/auth.php b/auth/nologin/auth.php index 29f018e4ddc..c3ed391c07c 100644 --- a/auth/nologin/auth.php +++ b/auth/nologin/auth.php @@ -85,6 +85,14 @@ class auth_plugin_nologin extends auth_plugin_base { return false; } + /** + * Returns true if plugin can be manually set. + * + * @return bool + */ + function can_be_manually_set() { + return true; + } } diff --git a/auth/none/auth.php b/auth/none/auth.php index 9d3bfc2d2ff..fcfce4cfd2d 100644 --- a/auth/none/auth.php +++ b/auth/none/auth.php @@ -115,6 +115,15 @@ class auth_plugin_none extends auth_plugin_base { return true; } + /** + * Returns true if plugin can be manually set. + * + * @return bool + */ + function can_be_manually_set() { + return true; + } + /** * Prints a form for configuring this authentication plugin. * diff --git a/lib/authlib.php b/lib/authlib.php index 5c7af4ae04f..dc5e97e195d 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -124,7 +124,6 @@ class auth_plugin_base { var $customfields = null; /** - * This is the primary method that is used by the authenticate_user_login() * function in moodlelib.php. * @@ -509,6 +508,21 @@ class auth_plugin_base { return false; } + /** + * Returns whether or not this authentication plugin can be manually set + * for users, for example, when bulk uploading users. + * + * This should be overriden by authentication plugins where setting the + * authentication method manually is allowed. + * + * @return bool + * @since 2.6 + */ + function can_be_manually_set() { + // Override if needed. + return false; + } + /** * Returns a list of potential IdPs that this authentication plugin supports. * This is used to provide links on the login page. @@ -550,7 +564,6 @@ class auth_plugin_base { return $this->customfields; } - } /**