MDL-8590 auth cleanup - part 4
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
+12
-3
@@ -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!');
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
+13
-12
@@ -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;
|
||||
|
||||
+21
-26
@@ -76,37 +76,32 @@ if ($show_instructions) {
|
||||
<div class="signuppanel">
|
||||
<h2><?php print_string("firsttime") ?></h2>
|
||||
<div class="subcontent">
|
||||
<?php switch ($authsequence[0]) {
|
||||
case "email":
|
||||
print_string("loginsteps", "", "signup.php");
|
||||
?>
|
||||
<?php if (is_enabled_auth('none')) { // instructions override the rest for security reasons
|
||||
print_string("loginstepsnone");
|
||||
} else if ($CFG->registerauth == 'email') {
|
||||
if (!empty($CFG->auth_instructions)) {
|
||||
echo format_text($CFG->auth_instructions);
|
||||
} else {
|
||||
print_string("loginsteps", "", "signup.php");
|
||||
} ?>
|
||||
<div class="signupform">
|
||||
<form action="signup.php" method="get" id="signup">
|
||||
<div><input type="submit" value="<?php print_string("startsignup") ?>" /></div>
|
||||
</form>
|
||||
</div>
|
||||
<?php break;
|
||||
|
||||
case "none":
|
||||
print_string("loginstepsnone");
|
||||
break;
|
||||
|
||||
default:
|
||||
echo format_text($CFG->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') ){
|
||||
?>
|
||||
<div class="signupform">
|
||||
<form action="signup.php" method="get" id="signup">
|
||||
<div><input type="submit" value="<?php print_string("startsignup") ?>" /></div>
|
||||
</form>
|
||||
</div>
|
||||
<?php }
|
||||
}
|
||||
?>
|
||||
<?php } else if (!empty($CFG->registerauth)) {
|
||||
echo format_text($CFG->auth_instructions);
|
||||
$authplugin = get_auth_plugin($CFG->registerauth);
|
||||
if (method_exists($authplugin, 'user_create')) { ?>
|
||||
<div class="signupform">
|
||||
<form action="signup.php" method="get" id="signup">
|
||||
<div><input type="submit" value="<?php print_string("startsignup") ?>" /></div>
|
||||
</form>
|
||||
</div>
|
||||
<?php }
|
||||
} else {
|
||||
echo format_text($CFG->auth_instructions);
|
||||
} ?>
|
||||
</div>
|
||||
</div>
|
||||
<?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);
|
||||
}
|
||||
|
||||
|
||||
+16
-15
@@ -3,14 +3,17 @@
|
||||
require_once('../config.php');
|
||||
require_once('signup_form.php');
|
||||
|
||||
//HTTPS is potentially required in this page
|
||||
httpsrequired();
|
||||
|
||||
$authplugin = get_auth_plugin($CFG->auth);
|
||||
|
||||
if ($CFG->auth != 'email' and (empty($CFG->auth_user_create) or !(method_exists($authplugin, 'user_create'))) ) {
|
||||
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.");
|
||||
}
|
||||
|
||||
//HTTPS is potentially required in this page
|
||||
httpsrequired();
|
||||
|
||||
$mform_signup = new login_signup_form_1();
|
||||
|
||||
@@ -25,19 +28,17 @@
|
||||
$user->firstaccess = time();
|
||||
$user->mnethostid = $CFG->mnet_localhost_id;
|
||||
$user->secret = random_string(15);
|
||||
$user->auth = $CFG->auth;
|
||||
$user->auth = $CFG->registerauth;
|
||||
|
||||
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.");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user