From 4f6aa35eb860bca481d59f9a9cab742bb7025a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Arenaza?= Date: Mon, 29 Aug 2011 13:56:54 +0200 Subject: [PATCH 1/2] MDL-29093 - Authentication for authentication only, not for user creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are cases when a moodle installation needs to only deal user authentication and not user creation (this is especially interesting when using external authentication sources such as LDAP, CAS, etc.) Add an option to prevent automatic user creation if the administrator does't want users to be automatically created. Signed-off-by: IƱaki Arenaza --- admin/settings/plugins.php | 1 + lang/en/admin.php | 2 ++ lib/moodlelib.php | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 599aa088cb3..8546e0a4faf 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -74,6 +74,7 @@ if ($hassiteconfig) { $temp->add(new admin_setting_manageauths()); $temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), '')); $temp->add(new admin_setting_special_registerauth()); + $temp->add(new admin_setting_configcheckbox('authonly', get_string('authonly', 'admin'), get_string('authonly_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('loginpageautofocus', get_string('loginpageautofocus', 'admin'), get_string('loginpageautofocus_help', 'admin'), 0)); $temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'), get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show')))); diff --git a/lang/en/admin.php b/lang/en/admin.php index 56e87aef4e4..2ce95f37d9a 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -59,6 +59,8 @@ $string['antivirus'] = 'Anti-Virus'; $string['appearance'] = 'Appearance'; $string['aspellpath'] = 'Path to aspell'; $string['authentication'] = 'Authentication'; +$string['authonly'] = 'Authentication for authentication only'; +$string['authonly_help'] = 'Enabling this option makes authentication plugins only authenticate already existing users. No new users will be created as part of the login process, even if entered username and password are valid. This also means you need to create new users using other mechanisms (manual creation, user uploading, LDAP sync, etc.)'; $string['authsettings'] = 'Manage authentication'; $string['autolang'] = 'Language autodetect'; $string['autologinguests'] = 'Auto-login guests'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index bfb8855e163..16a6436060c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -3769,8 +3769,12 @@ function authenticate_user_login($username, $password) { $user = update_user_record($username); } } else { - // if user not found, create him - $user = create_user_record($username, $password, $auth); + // if user not found and user creation is not disabled, create it + if (empty($CFG->authonly)) { + $user = create_user_record($username, $password, $auth); + } else { + continue; + } } $authplugin->sync_roles($user); From 2c7a91475f157c0d6f6bde0691217dbc140c4d88 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Tue, 13 Sep 2011 15:06:40 +1200 Subject: [PATCH 2/2] MDL-29093 - Authentication improved new setting name and strings --- admin/settings/plugins.php | 2 +- lang/en/admin.php | 4 ++-- lib/moodlelib.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 8546e0a4faf..0e86f80d6df 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -74,7 +74,7 @@ if ($hassiteconfig) { $temp->add(new admin_setting_manageauths()); $temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), '')); $temp->add(new admin_setting_special_registerauth()); - $temp->add(new admin_setting_configcheckbox('authonly', get_string('authonly', 'admin'), get_string('authonly_help', 'admin'), 0)); + $temp->add(new admin_setting_configcheckbox('authpreventaccountcreation', get_string('authpreventaccountcreation', 'admin'), get_string('authpreventaccountcreation_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('loginpageautofocus', get_string('loginpageautofocus', 'admin'), get_string('loginpageautofocus_help', 'admin'), 0)); $temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'), get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show')))); diff --git a/lang/en/admin.php b/lang/en/admin.php index 2ce95f37d9a..e0cce9e7407 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -59,8 +59,8 @@ $string['antivirus'] = 'Anti-Virus'; $string['appearance'] = 'Appearance'; $string['aspellpath'] = 'Path to aspell'; $string['authentication'] = 'Authentication'; -$string['authonly'] = 'Authentication for authentication only'; -$string['authonly_help'] = 'Enabling this option makes authentication plugins only authenticate already existing users. No new users will be created as part of the login process, even if entered username and password are valid. This also means you need to create new users using other mechanisms (manual creation, user uploading, LDAP sync, etc.)'; +$string['authpreventaccountcreation'] = 'Prevent account creation when authenticating'; +$string['authpreventaccountcreation_help'] = 'When a user authenticates, if they do not yet have an account on the site, usually one will be automatically created for them. It may be that you wish to authenticate using an external system, but you wish to restrict access to the site to users with an existing account only. With this option enabled, only existing users will be able to gain access after they are authenticated via the external system. New accounts will need to be created manually or via the upload users feature.'; $string['authsettings'] = 'Manage authentication'; $string['autolang'] = 'Language autodetect'; $string['autologinguests'] = 'Auto-login guests'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 16a6436060c..ff43829b23c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -3770,7 +3770,7 @@ function authenticate_user_login($username, $password) { } } else { // if user not found and user creation is not disabled, create it - if (empty($CFG->authonly)) { + if (empty($CFG->authpreventaccountcreation)) { $user = create_user_record($username, $password, $auth); } else { continue;