]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8590 auth cleanup - part 4
authorskodak <skodak>
Tue, 20 Feb 2007 17:24:19 +0000 (17:24 +0000)
committerskodak <skodak>
Tue, 20 Feb 2007 17:24:19 +0000 (17:24 +0000)
login/change_password.php
login/confirm.php
login/forgot_password.php
login/index.php
login/index_form.html
login/mnet_email.php
login/signup.php
login/signup_form.php

index f9e55c4e120025e7a1c529a77574d521ca73fe30..08896e4b0d66abde4ecfb7282929c20ddb33a50f 100644 (file)
@@ -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');
             }
index 51c4b6f3d74f86bef6c0b5c343799f117d2aeb6a..bef52d37f4223a6f48be417d71f49e66ff7eeb35 100644 (file)
@@ -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!');
                     }
index f029c730369fd3e10ce579d5181311c8ac844baa..520b4137812fcbef6769c11fb08061cf8505fad4 100644 (file)
@@ -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()) {
index 579d86b742295ba8e3a4c50b58136bb9ca46c83c..52bb75a03ef52cfc7fa97a3e3f5a97f1c0f07f53 100644 (file)
 /// 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;
index ae4e10458b2011afb9feab05f5141aa9d47dd40f..0bcecc985494954a1526bec4ca46e139209ad872 100644 (file)
@@ -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 } ?>
index dc2fa96ec59f8b6d3aa076f3063a4c3ca58fbfd7..0d3e69b10ea05bf5e5a5e5f33ec24cdf31bee65a 100644 (file)
@@ -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);
 }
 
index c4c86591599f0e8deecbc3ef353b4a6a11e29789..a372f83f6a00a13eb4d99a20376e76c3fb6e456e 100644 (file)
@@ -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()) {
         $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;
     }
index 8b60857f4b5c69a99d540964c608207d95db849b..77849f250d355d745da96902ef54a7031decc086 100644 (file)
@@ -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');
                        }