More moving functions around and removal of hardcoded SQL
This commit is contained in:
+2
-1
@@ -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";
|
||||
|
||||
@@ -160,6 +160,7 @@ $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['feedback'] = "Feedback";
|
||||
|
||||
+96
-23
@@ -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 ...
|
||||
|
||||
+11
-9
@@ -20,24 +20,26 @@
|
||||
|
||||
$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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -104,15 +104,4 @@
|
||||
|
||||
// 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'");
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user