]> git.mjollnir.org Git - moodle.git/commitdiff
More moving functions around and removal of hardcoded SQL
authormoodler <moodler>
Mon, 23 Dec 2002 03:07:01 +0000 (03:07 +0000)
committermoodler <moodler>
Mon, 23 Dec 2002 03:07:01 +0000 (03:07 +0000)
lang/en/moodle.php
lang/en_us/moodle.php
lib/moodlelib.php
login/confirm.php
login/forgot_password.php
login/index.php
login/signup.php

index 82b9803312d7dfb8deabeeb45b9e5b7919acdacb..8d9c3aa2d5f5d22179c37148fd4d15c778582a04 100644 (file)
@@ -163,9 +163,10 @@ $string['enrolmentkeyhint'] = "That enrolment key was incorrect, please try agai
 $string['entercourse'] = "Click to enter this course";
 $string['enteremailaddress'] = "Enter in your email address to reset your 
    password and have the new password sent to you via email.";
+$string['error'] = "Error";
+$string['errortoomanylogins'] = "Sorry, you have exceeded the allowed number of login attempts. Restart your browser.";
 $string['existingadmins'] = "Existing admins";
 $string['existingteachers'] = "Existing teachers";
-$string['error'] = "Error";
 $string['feedback'] = "Feedback";
 $string['filemissing'] = "\$a is missing";
 $string['files'] = "Files";
index 0f69d8964ca1fcbbdc9396d7119ecac006a520fb..f3d5dc56ab6fad2ba124e2a50c6905b9e2af5176 100644 (file)
@@ -160,6 +160,7 @@ $string['entercourse'] = "Click to enter this course";
 $string['enteremailaddress'] = "Enter in your email address to reset your \r
    password and have the new password sent to you via email.";
 $string['error'] = "Error";
+$string['errortoomanylogins'] = "Sorry, you have exceeded the allowed number of login attempts. Restart your browser.";
 $string['existingadmins'] = "Existing admins";
 $string['existingteachers'] = "Existing teachers";
 $string['feedback'] = "Feedback";
index b72d0849fbe1b8a91b0c86d3595e18e9fcab7b54..462b694eb9f333b690f4cbd2b50dceaf0764dea3 100644 (file)
@@ -310,6 +310,18 @@ function require_login($courseid=0) {
     }
 }
 
+function update_user_login_times() {
+    global $USER;
+
+    $USER->lastlogin = $user->lastlogin = $USER->currentlogin;
+    $USER->currentlogin = $user->currentlogin = time();
+    save_session("USER");
+
+    $user->id = $USER->id;
+
+    return update_record("user", $user);
+}
+
 
 function update_login_count() {
 /// Keeps track of login attempts
@@ -328,7 +340,7 @@ function update_login_count() {
     if ($SESSION->logincount > $max_logins) {
         unset($SESSION->wantsurl);
         save_session("SESSION");
-        error("Sorry, you have exceeded the allowed number of login attempts. Restart your browser.");
+        error(get_string("errortoomanylogins"));
     }
 }
 
@@ -341,7 +353,6 @@ function reset_login_count() {
 }
 
 
-
 function isadmin($userid=0) {
 /// Is the user an admin?
     global $USER;
@@ -645,6 +656,54 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $a
     }
 }
 
+function reset_password_and_mail($user) {
+
+    global $CFG;
+
+    $site  = get_site();
+    $from = get_admin();
+
+    $newpassword = generate_password();
+
+    if (! set_field("user", "password", md5($newpassword), "id", $user->id) ) {
+        error("Could not set user password!");
+    }
+
+    $a->firstname = $user->firstname;
+    $a->sitename = $site->fullname;
+    $a->username = $user->username;
+    $a->newpassword = $newpassword;
+    $a->link = "$CFG->wwwroot/login/change_password.php";
+    $a->signoff = "$from->firstname $from->lastname ($from->email)";
+
+    $message = get_string("newpasswordtext", "", $a);
+
+    $subject  = "$site->fullname: ".get_string("changedpassword");
+
+    return email_to_user($user, $from, $subject, $message);
+
+}
+
+function send_confirmation_email($user) {
+
+    global $CFG;
+
+    $site = get_site();
+    $from = get_admin();
+
+    $data->firstname = $user->firstname;
+    $data->sitename = $site->fullname;
+    $data->link = "$CFG->wwwroot/login/confirm.php?p=$user->secret&s=$user->username";
+    $data->admin = "$from->firstname $from->lastname ($from->email)";
+
+    $message = get_string("emailconfirmation", "", $data);
+    $subject = "$site->fullname account confirmation";
+
+    return email_to_user($user, $from, $subject, $message);
+
+}
+
+
 
 /// FILE HANDLING  /////////////////////////////////////////////
 
@@ -890,27 +949,6 @@ function get_list_of_languages() {
     return $languages;
 }
 
-function get_list_of_plugins($plugin="mod") {
-/// Lists plugin directories within some directory
-
-    global $CFG;
-
-    $basedir = opendir("$CFG->dirroot/$plugin");
-    while ($dir = readdir($basedir)) {
-        if ($dir == "." || $dir == ".." || $dir == "CVS") {
-            continue;
-        }
-        if (filetype("$CFG->dirroot/$plugin/$dir") != "dir") {
-            continue;
-        }
-        $plugins[] = $dir;
-    }
-    if ($plugins) {
-        asort($plugins);
-    }
-    return $plugins;
-}
-
 
 /// ENCRYPTION  ////////////////////////////////////////////////
 
@@ -984,6 +1022,27 @@ function endecrypt ($pwd, $data, $case) {
 
 /// ENVIRONMENT CHECKING  ////////////////////////////////////////////////////////////
 
+function get_list_of_plugins($plugin="mod") {
+/// Lists plugin directories within some directory
+
+    global $CFG;
+
+    $basedir = opendir("$CFG->dirroot/$plugin");
+    while ($dir = readdir($basedir)) {
+        if ($dir == "." || $dir == ".." || $dir == "CVS") {
+            continue;
+        }
+        if (filetype("$CFG->dirroot/$plugin/$dir") != "dir") {
+            continue;
+        }
+        $plugins[] = $dir;
+    }
+    if ($plugins) {
+        asort($plugins);
+    }
+    return $plugins;
+}
+
 function check_php_version($version="4.1.0") {
 /// Returns true is the current version of PHP is greater that the specified one
     $minversion = intval(str_replace(".", "", $version));
@@ -1084,6 +1143,20 @@ function count_words($string) {
     return count(preg_split("/\w\b/", $string)) - 1;
 }
 
+function random_string ($length=15) {
+    $pool  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    $pool .= "abcdefghijklmnopqrstuvwxyz";
+    $pool .= "0123456789";
+    $poollen = strlen($pool);
+    mt_srand ((double) microtime() * 1000000);
+    $string = "";
+    for ($i = 0; $i < $length; $i++) {
+        $string .= substr($pool, (mt_rand()%($poollen)), 1);
+    }
+    return $string;
+}
+
+
 function getweek ($startdate, $thedate) {
 /// Given dates in seconds, how many weeks is the date from startdate
 /// The first week is 1, the second 2 etc ... 
index b5239171040ec342196b6e364dd8572ccbe02897..8091d83249964f817b1b54b586cd7e989d3b8df5 100644 (file)
 
                                $USER = $user;
 
-                               $timenow = time();
-
-                               $rs = $db->Execute("UPDATE user SET confirmed=1, lastIP='$REMOTE_ADDR', 
-                                                                                                       firstaccess='$timenow', lastaccess='$timenow'
-                                                                       WHERE id = '$USER->id' ");
-                               if (!$rs) {
-                    error("Could not update this user while confirming");
+                if (!set_field("user", "confirmed", 1, "id", $USER->id)) {
+                    error("Could not confirm this user!");
+                }
+                if (!set_field("user", "firstaccess", time(), "id", $USER->id)) {
+                    error("Could not set this user's first access date!");
+                }
+                if (!update_user_in_db($USER->id)) {
+                    error("Could not update this user's information");
                 }
 
                                set_moodle_cookie($USER->username);
 
+                // The user has confirmed successfully, let's log them in
+
                                $USER->loggedin = true;
                                $USER->confirmed = 1;
                                $USER->site = $CFG->wwwroot;
-
                 save_session("USER");
 
-                               if ( ! empty($SESSION->wantsurl) ) {
+                               if ( ! empty($SESSION->wantsurl) ) {   // Send them where they were going
                                        $goto = $SESSION->wantsurl;
                     unset($SESSION->wantsurl);
                     save_session("SESSION");
index 187282dc73709f6dc8aed69bba76986795d84141..8da98a7be39a2b9f8febdd20797693543e124413 100644 (file)
@@ -67,32 +67,4 @@ function validate_form($frm, &$err) {
 }
 
 
-function reset_password_and_mail($user) {
-
-    global $CFG;
-
-    $site  = get_site();
-    $from = get_admin();
-
-    $newpassword = generate_password();
-
-    if (! set_field("user", "password", md5($newpassword), "id", $user->id) ) {
-        error("Could not set user password!");
-    }
-
-    $a->firstname = $user->firstname;
-    $a->sitename = $site->fullname;
-    $a->username = $user->username;
-    $a->newpassword = $newpassword;
-    $a->link = "$CFG->wwwroot/login/change_password.php";
-    $a->signoff = "$from->firstname $from->lastname ($from->email)";
-
-    $message = get_string("newpasswordtext", "", $a);
-
-    $subject  = "$site->fullname: ".get_string("changedpassword");
-
-    return email_to_user($user, $from, $subject, $message);
-
-}
-
 ?>
index b23d80940f12d8d32a5f72a7190628ef9cc7583c..c41db4cd7cd6fecbe3baad7c3974d4c1643e060f 100644 (file)
 
     // No footer on this page
 
-function update_user_login_times() {
-    global $db, $USER;
-
-    $USER->lastlogin = $USER->currentlogin;
-    $USER->currentlogin = time();
-    save_session("USER");
-
-    return $db->Execute("UPDATE user 
-                         SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
-                         WHERE id = '$USER->id'");
-}
 ?>
index c3988fc36821e12c2bad9fcf037c039f4ee181f1..6911550198bcc74e7e1ac0be657d4550920cfde8 100644 (file)
@@ -100,39 +100,4 @@ function validate_form($user, &$err) {
 }
 
 
-function random_string ($length=15) {
-    $pool  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-    $pool .= "abcdefghijklmnopqrstuvwxyz";
-    $pool .= "0123456789";
-    $poollen = strlen($pool);
-    mt_srand ((double) microtime() * 1000000);
-    $string = "";
-    for ($i = 0; $i < $length; $i++) {
-        $string .= substr($pool, (mt_rand()%($poollen)), 1);
-    }
-    return $string;
-}
-
-
-function send_confirmation_email($user) {
-
-    global $CFG;
-
-    $site = get_site();
-    $from = get_admin();
-
-    $data->firstname = $user->firstname;
-    $data->sitename = $site->fullname;
-    $data->link = "$CFG->wwwroot/login/confirm.php?p=$user->secret&s=$user->username";
-    $data->admin = "$from->firstname $from->lastname ($from->email)";
-
-    $message = get_string("emailconfirmation", "", $data);
-    $subject = "$site->fullname account confirmation";
-
-    return email_to_user($user, $from, $subject, $message);
-
-}
-
-
-
 ?>