From 3fe6b721e239f4f72e234ecc7b39737e8a4bdf08 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 20 Feb 2007 17:24:19 +0000 Subject: [PATCH] MDL-8590 auth cleanup - part 4 --- login/change_password.php | 2 -- login/confirm.php | 15 ++++++++++--- login/forgot_password.php | 6 +---- login/index.php | 25 +++++++++++---------- login/index_form.html | 47 +++++++++++++++++---------------------- login/mnet_email.php | 2 +- login/signup.php | 31 +++++++++++++------------- login/signup_form.php | 4 ++-- 8 files changed, 66 insertions(+), 66 deletions(-) diff --git a/login/change_password.php b/login/change_password.php index f9e55c4e12..08896e4b0d 100644 --- a/login/change_password.php +++ b/login/change_password.php @@ -58,8 +58,6 @@ $userauth = get_auth_plugin($user->auth); if ($userauth->can_change_password()){ if ($userauth->user_update_password($user, $data->newpassword1)) { - // hash the $user->password field (without local db update) - update_internal_user_password($user, $data->newpassword1, false); } else { error('Could not set the new password'); } diff --git a/login/confirm.php b/login/confirm.php index 51c4b6f3d7..bef52d37f4 100644 --- a/login/confirm.php +++ b/login/confirm.php @@ -7,6 +7,15 @@ $p = optional_param('p', '', PARAM_ALPHANUM); // Old parameter: secret $s = optional_param('s', '', PARAM_CLEAN); // Old parameter: username + if (empty($CFG->registerauth)) { + error("Sorry, you may not use this page."); + } + $authplugin = get_auth_plugin($CFG->registerauth); + + if (!method_exists($authplugin, 'user_create')) { + error("Sorry, you may not use this page."); + } + if (!empty($data) || (!empty($p) && !empty($s))) { if (!empty($data)) { @@ -18,7 +27,7 @@ $username = $s; } - $authplugin = get_auth_plugin('email'); + $authplugin = get_auth_plugin($CFG->registerauth); $confirmed = $authplugin->user_confirm($username, $usersecret); if ($confirmed == AUTH_CONFIRM_ALREADY) { @@ -32,8 +41,8 @@ } if ($confirmed == AUTH_CONFIRM_OK) { // Activate new user if necessary - $authplugin = get_auth_plugin($CFG->auth); - if (isset($CFG->auth_user_create) and $CFG->auth_user_create == 1 and method_exists($authplugin, 'user_activate') ) { + $authplugin = get_auth_plugin($CFG->registerauth); + if (method_exists($authplugin, 'user_activate')) { if (!$authplugin->user_activate($username)) { error('Could not activate this user!'); } diff --git a/login/forgot_password.php b/login/forgot_password.php index f029c73036..520b413781 100644 --- a/login/forgot_password.php +++ b/login/forgot_password.php @@ -42,14 +42,10 @@ $page = ''; // page to display // if you are logged in then you shouldn't be here! -if (isloggedin() && !isguest()) { +if (isloggedin() && !isguestuser()) { redirect($CFG->wwwroot.'/index.php', $strloginalready, 5); } -// instantiate default auth -$auth = $CFG->auth; // the 'default' authentication method -$defaultauth = get_auth_plugin($auth); - $mform = new login_forgot_password_form(); if ($mform->is_cancelled()) { diff --git a/login/index.php b/login/index.php index 579d86b742..52bb75a03e 100644 --- a/login/index.php +++ b/login/index.php @@ -41,17 +41,21 @@ /// Load alternative login screens if necessary -// check if auth config broken (old config --> multi config) -if (empty($CFG->auth_plugins_enabled) and ! empty($CFG->auth)) { - set_config('auth_plugins_enabled', $CFG->auth); -} -$authsequence = explode(',', $CFG->auth_plugins_enabled); // auths, in sequence +$authsequence = explode(',', $CFG->auth); // auths, in sequence // Load alternative login screens if necessary if ($authsequence[0] == 'cas' and !empty($CFG->cas_enabled)) { require($CFG->dirroot.'/auth/cas/login.php'); } +if (!isset($CFG->registerauth)) { + set_config('registerauth', ''); +} + +if (!isset($CFG->auth_instructions)) { + set_config('auth_instructions', ''); +} + // See http://moodle.org/mod/forum/discuss.php?d=39918#187611 // if ($CFG->auth == 'shibboleth') { // if (!empty($SESSION->shibboleth_checked) ) { // Just come from there @@ -114,7 +118,7 @@ if ($authsequence[0] == 'cas' and !empty($CFG->cas_enabled)) { $frm->username = trim(moodle_strtolower($frm->username)); - if ($CFG->auth == 'none' && empty($CFG->extendedusernamechars)) { + if (is_enabled_auth('none') && empty($CFG->extendedusernamechars)) { $string = eregi_replace("[^(-\.[:alnum:])]", "", $frm->username); if (strcmp($frm->username, $string)) { $errormsg = get_string('username').': '.get_string("alphanumerical"); @@ -264,7 +268,7 @@ if ($authsequence[0] == 'cas' and !empty($CFG->cas_enabled)) { set_moodle_cookie('nobody'); // To help search for cookies } -if (empty($frm->username) && $authsequence[0] != 'shibboleth') { // See bug 5184 + if (empty($frm->username) && $authsequence[0] != 'shibboleth') { // See bug 5184 $frm->username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie(); $frm->password = ""; } @@ -274,11 +278,8 @@ if (empty($frm->username) && $authsequence[0] != 'shibboleth') { // See bug 518 } else { $focus = "username"; } - - if (isset($CFG->auth_instructions)) { - $CFG->auth_instructions = trim($CFG->auth_instructions); - } -if ($authsequence[0] == "email" or $authsequence[0] == "none" or !empty($CFG->auth_instructions)) { + + if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($CFG->auth_instructions)) { $show_instructions = true; } else { $show_instructions = false; diff --git a/login/index_form.html b/login/index_form.html index ae4e10458b..0bcecc9854 100644 --- a/login/index_form.html +++ b/login/index_form.html @@ -76,37 +76,32 @@ if ($show_instructions) {

- +registerauth == 'email') { + if (!empty($CFG->auth_instructions)) { + echo format_text($CFG->auth_instructions); + } else { + print_string("loginsteps", "", "signup.php"); + } ?>
" />
-auth_instructions); - // TODO: if !function_exists(auth_user_login) then require_once /auth/$CFG->auth/lib.php - // ..which implies that auth_user_login might have been floating - // about in global namespace. grr - $authplugin = get_auth_plugin($CFG->auth); - if (!empty($CFG->auth_user_create) and method_exists($authplugin, 'user_create') ){ -?> -
-
-
" />
-
-
- +registerauth)) { + echo format_text($CFG->auth_instructions); + $authplugin = get_auth_plugin($CFG->registerauth); + if (method_exists($authplugin, 'user_create')) { ?> +
+
+
" />
+
+
+auth_instructions); + } ?>
diff --git a/login/mnet_email.php b/login/mnet_email.php index dc2fa96ec5..0d3e69b10e 100644 --- a/login/mnet_email.php +++ b/login/mnet_email.php @@ -7,7 +7,7 @@ $username = required_param('u', PARAM_ALPHANUM); $sesskey = sesskey(); // if you are logged in then you shouldn't be here -if (isloggedin() and !isguest()) { +if (isloggedin() and !isguestuser()) { redirect( $CFG->wwwroot.'/', get_string('loginalready'), 5); } diff --git a/login/signup.php b/login/signup.php index c4c8659159..a372f83f6a 100644 --- a/login/signup.php +++ b/login/signup.php @@ -3,15 +3,18 @@ require_once('../config.php'); require_once('signup_form.php'); - //HTTPS is potentially required in this page - httpsrequired(); - - $authplugin = get_auth_plugin($CFG->auth); + if (empty($CFG->registerauth)) { + error("Sorry, you may not use this page."); + } + $authplugin = get_auth_plugin($CFG->registerauth); - if ($CFG->auth != 'email' and (empty($CFG->auth_user_create) or !(method_exists($authplugin, 'user_create'))) ) { + if (!method_exists($authplugin, 'user_create')) { error("Sorry, you may not use this page."); } + //HTTPS is potentially required in this page + httpsrequired(); + $mform_signup = new login_signup_form_1(); if ($mform_signup->is_cancelled()) { @@ -25,19 +28,17 @@ $user->firstaccess = time(); $user->mnethostid = $CFG->mnet_localhost_id; $user->secret = random_string(15); - $user->auth = $CFG->auth; - - if (!empty($CFG->auth_user_create) and method_exists($authplugin, 'user_create') ){ - if (! $authplugin->user_exists($user->username)) { - if (! $authplugin->user_create($user, $plainpass)) { - error("Could not add user to authentication module!"); - } - } else { - error("User already exists on authentication database."); + $user->auth = $CFG->registerauth; + + if (! $authplugin->user_exists($user->username)) { + if (! $authplugin->user_create($user, $plainpass)) { + error("Could not add user to authentication module!"); } + } else { + error("User already exists on authentication database."); } - $authplugin = get_auth_plugin($CFG->auth); + $authplugin = get_auth_plugin($CFG->registerauth); $signedup = $authplugin->user_signup($user, $notify=true); exit; } diff --git a/login/signup_form.php b/login/signup_form.php index 8b60857f4b..77849f250d 100644 --- a/login/signup_form.php +++ b/login/signup_form.php @@ -64,7 +64,7 @@ class login_signup_form_1 extends moodleform { global $CFG; $errors = array(); - $authplugin = get_auth_plugin($CFG->auth); + $authplugin = get_auth_plugin($CFG->registerauth); if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) { $errors['username'] = get_string('usernameexists'); @@ -76,7 +76,7 @@ class login_signup_form_1 extends moodleform { } } } - if (isset($CFG->auth_user_create) and $CFG->auth_user_create==1 and method_exists($authplugin, 'user_exists')){ + if (method_exists($authplugin, 'user_exists')){ if ($authplugin->user_exists($user->username)) { $errors['username'] = get_string('usernameexists'); } -- 2.39.5