From 11ee95dadc408e16e9832af9fd0b41495e78b0a6 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 19 Oct 2000 13:31:23 +0000 Subject: A big, fat commit with a shitload of internal changes. Not that much visual changes: - removed redundant files user.class.php, calendar.class.php and backend.class.php. - converted *all* mysql queries to queries supported by the database abstraction layer. - expanded the watchdog to record more information on what actually happened. - bugfix: anonymous readers where not able to view comments. - bugfix: anonymous readers could gain read-only access to the submission queue. - bugfix: invalid includes in backend.php - bugfix: invalid use of '$user->block' and last but not least: - redid 50% of the user account system --- account.php | 266 +++++++++++++++++++++++++------------------ admin.php | 16 +-- diary.php | 1 - discussion.php | 55 ++++----- faq.php | 14 +++ includes/backend.class.php | 241 --------------------------------------- includes/calendar.class.php | 76 ------------- includes/config.inc | 16 +-- includes/database.inc | 5 +- includes/function.inc | 25 +--- includes/submission.inc | 14 ++- includes/template.inc | 8 +- includes/user.inc | 41 +++---- index.php | 2 +- submission.php | 2 +- submit.php | 2 +- themes/marvin/marvin.theme | 22 ++-- themes/unconed/unconed.theme | 22 ++-- 18 files changed, 274 insertions(+), 554 deletions(-) delete mode 100644 includes/backend.class.php delete mode 100644 includes/calendar.class.php diff --git a/account.php b/account.php index 2c30239f5..ffeb263f2 100644 --- a/account.php +++ b/account.php @@ -8,35 +8,37 @@ function account_get_user($uname) { return db_fetch_object($result); } -function account_login($userid = "") { +function account_login() { $output .= "
\n"; $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; + $output .= " \n"; + $output .= " \n"; + $output .= " \n"; $output .= "
User ID:
Password:
Register as new user.
$user->ublock
Username:
Password:
\n"; $output .= "
\n"; + $output .= "You don't have an account yet? Register as new user.\n"; + return $output; } function account_session_start($userid, $passwd) { global $user; - session_start(); + $user = new User($userid, $passwd); - if ($user && user_valid()) { + + if ($user->id) { + session_start(); session_register("user"); - watchdog(1, "session opened for user `$user->userid'."); + watchdog(1, "session opened for user `$user->userid'"); } else { - watchdog(2, "failed login for user `$userid'."); + watchdog(2, "failed login for user `$userid'"); } } function account_session_close() { global $user; - watchdog(1, "session closed for user `$user->userid'."); + watchdog(1, "$user->userid: sucessful attempt to logout"); session_unset(); session_destroy(); unset($user); @@ -45,18 +47,21 @@ function account_session_close() { function account_user_edit() { global $theme, $user; - if ($user->id && user_valid()) { + if ($user->id) { ### Generate output/content: $output .= "
\n"; + $output .= "Username:
\n"; + $output .= "  $user->userid

\n"; + $output .= "Required, unique, and can not be changed.

\n"; $output .= "Real name:
\n"; $output .= "name\">
\n"; $output .= "Optional.

\n"; $output .= "Real e-mail address:
\n"; - $output .= "email\">
\n"; - $output .= "Required, but never displayed publicly: needed in case you lose your password.

\n"; + $output .= "  $user->real_email

\n"; + $output .= "Required, unique, can not be changed and is never displayed publicly: only needed in case you lose your password.

\n"; $output .= "Fake e-mail address:
\n"; - $output .= "femail\">
\n"; - $output .= "Optional, and displayed publicly by your comments. You may spam proof it if you want.

\n"; + $output .= "fake_email\">
\n"; + $output .= "Optional, and displayed publicly. You may spam proof your real e-mail address if you want.

\n"; $output .= "URL of homepage:
\n"; $output .= "url\">
\n"; $output .= "Optional, but make sure you enter fully qualified URLs only. That is, remember to include \"http://\".

\n"; @@ -67,7 +72,7 @@ function account_user_edit() { $output .= "
\n"; $output .= "Optional. This information will be publicly displayed at the end of your comments.

\n"; $output .= "Password:
\n"; - $output .= "
\n"; + $output .= "
\n"; $output .= "Enter your new password twice if you want to change your current password or leave it blank if you are happy with your current password.

\n"; $output .= "
\n"; $output .= "

\n"; @@ -79,30 +84,30 @@ function account_user_edit() { } else { $theme->header(); - $theme->box("Login", account_login($userid)); + $theme->box("Login", account_login()); $theme->footer(); } } function account_user_save($edit) { global $user; - if ($user && user_valid()) { + if ($user->id) { $data[name] = $edit[name]; - $data[email] = $edit[email]; - $data[femail] = $edit[femail]; + $data[fake_email] = $edit[fake_email]; $data[url] = $edit[url]; $data[bio] = $edit[bio]; $data[signature] = $edit[signature]; - if ($edit[pass1] == $edit[pass2] && !empty($edit[pass1])) { $data[passwd] = $edit[pass1]; } - dbsave("users", $data, $user->id); - user_rehash(); + + if ($edit[pass1] && $edit[pass1] == $edit[pass2]) $data[passwd] = $edit[pass1]; + + user_save($data, $user->id); } } function account_page_edit() { global $theme, $themes, $user; - if ($user && user_valid()) { + if ($user->id) { ### Generate output/content: $output .= "
\n"; $output .= "Theme:
\n"; @@ -115,27 +120,27 @@ function account_page_edit() { $output .= "
\n"; $output .= "Selecting a different theme will change the look and feel of the site.

\n"; $output .= "Maximum number of stories:
\n"; - $output .= "storynum\">

\n"; + $output .= "stories\">

\n"; $output .= "The maximum number of stories that will be displayed on the main page.

\n"; - $options = ""; - $options .= ""; - $options .= ""; + $options = ""; + $options .= ""; + $options .= ""; $output .= "Comment display mode:
\n"; - $output .= "

\n"; - $options = ""; - $options .= ""; - $options .= ""; + $output .= "

\n"; + $options = ""; + $options .= ""; + $options .= ""; $output .= "Comment sort order:
\n"; - $output .= "

\n"; - $options = ""; - $options .= ""; - $options .= ""; - $options .= ""; - $options .= ""; - $options .= ""; - $options .= ""; + $output .= "

\n"; + $options = ""; + $options .= ""; + $options .= ""; + $options .= ""; + $options .= ""; + $options .= ""; + $options .= ""; $output .= "Comment threshold:
\n"; - $output .= "
\n"; + $output .= "
\n"; $output .= "Comments that scored less than this setting will be ignored. Anonymous comments start at 0, comments of people logged on start at 1 and moderators can add and subtract points.

\n"; $output .= "
\n"; $output .= "

\n"; @@ -147,33 +152,32 @@ function account_page_edit() { } else { $theme->header(); - $theme->box("Login", account_login($userid)); + $theme->box("Login", account_login()); $theme->footer(); } } function account_page_save($edit) { global $user; - if ($user && user_valid()) { + if ($user->id) { $data[theme] = $edit[theme]; - $data[storynum] = $edit[storynum]; - $data[umode] = $edit[umode]; - $data[uorder] = $edit[uorder]; - $data[thold] = $edit[thold]; - dbsave("users", $data, $user->id); - user_rehash(); + $data[stories] = $edit[stories]; + $data[mode] = $edit[mode]; + $data[sort] = $edit[sort]; + $data[threshold] = $edit[threshold]; + user_save($data, $user->id); } } function account_user($uname) { global $user, $theme; - if ($user && $uname && $user->userid == $uname) { + if ($user->id && $user->userid == $uname) { $output .= "

Welcome $user->userid! This is your user info page. There are many more, but this one is yours. You are probably most interested in editing something, but if you need to kill some time, this place is as good as any other place.

\n"; $output .= "\n"; $output .= " \n"; $output .= " \n"; - $output .= " \n"; + $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; @@ -187,7 +191,7 @@ function account_user($uname) { elseif ($uname && $account = account_get_user($uname)) { $box1 .= "
User ID:$user->userid
Name:". format_data($user->name) ."
E-mail:". format_email_address($user->femail) ."
E-mail:". format_email_address($user->fake_email) ."
URL:". format_url($user->url) ."
Bio:". format_data($user->bio) ."
Signature:". format_data($user->signature) ."
\n"; $box1 .= " \n"; - $box1 .= " \n"; + $box1 .= " \n"; $box1 .= " \n"; $box1 .= " \n"; $box1 .= "
Username:$account->userid
E-mail:". format_email_address($account->femail) ."
E-mail:". format_email_address($account->fake_email) ."
URL:". format_url($account->url) ."
Bio:". format_data($account->bio) ."
\n"; @@ -219,50 +223,51 @@ function account_user($uname) { else { ### Display login form: $theme->header(); - $theme->box("Login", account_login($userid)); + $theme->box("Login", account_login()); $theme->footer(); } } -function account_register() { - if ($rval = account_validate($new)) { - account_new($new, "Error: $rval"); - } - else { - ### Generate new password: - $new[passwd] = account_password(); - dbsave("users", $new); - - if ($mail == 1) { - ### Display account information: - $theme->header(); - $theme->box("Account details", "Your password is: $new[passwd]
Login to change your personal settings."); - $theme->footer(); - } - else { - ### Send e-mail with account details: - mail($new[email], "Account details for $sitename", "$new[userid],\n\nyour $sitename member account has been created succesfully. To be able to use it, you must login using the information below. Please save this mail for further reference.\n\n username: $new[userid]\n e-mail: $new[email]\n password: $new[passwd]\n\nThis password is generated by a randomizer. It is recommended that you change this password immediately.\n\n$contact_signature", "From: $contact_email\nX-Mailer: PHP/" . phpversion()); +function account_validate($user) { + include "includes/ban.inc"; - ### Display account information: - $theme->header(); - $theme->box("Account details", "Your member account has been created and the details necessary to login have been sent to your e-mail account $new[email]. Once you received the account confirmation, hit this link to login."); - $theme->footer(); - } - watchdog(1, "new user `$new[userid]' registered with e-mail address `$new[email]'"); - } + ### Verify username and e-mail address: + $user[userid] = trim($user[userid]); + if (empty($user[real_email]) || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $user[real_email]))) $error .= "
  • the specified e-mail address is not valid.
  • \n"; + if (empty($user[userid]) || (ereg("[^a-zA-Z0-9_-]", $user[userid]))) $error .= "
  • the specified username is not valid.
  • \n"; + if (strlen($user[userid]) > 15) $error .= "
  • the specified username is too long: it must be less than 15 characters.
  • \n"; + + ### Check to see whether the username or e-mail address are banned: + if ($ban = ban_match($user[userid], $type2index[usernames])) $error .= "
  • the specified username is banned for the following reason: $ban->reason.
  • \n"; + if ($ban = ban_match($user[real_email], $type2index[addresses])) $error .= "
  • the specified e-mail address is banned for the following reason: $ban->reason.
  • \n"; + + ### Verify whether username and e-mail address are unique: + if (db_num_rows(db_query("SELECT userid FROM users WHERE LOWER(userid) = LOWER('$user[userid]')")) > 0) $error .= "
  • the specified username is already taken.
  • \n"; + if (db_num_rows(db_query("SELECT real_email FROM users WHERE LOWER(real_email)=LOWER('$user[real_email]')")) > 0) $error .= "
  • the specified e-mail address is already registered.
  • \n"; + + return $error; } -function account_new($user = "", $error = "") { +function account_register_enter($user = "", $error = "") { global $theme; - $output .= "
    \n"; - $output .= "\n"; - if (!empty($error)) $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - $output .= "
    $error
    Name:
    User ID:
    E-mail:
    \n"; + if ($error) $output .= "Failed to register.$error\n"; + else $output .= "

    Registering allows you to comment on stories, to moderate comments and pending stories, to maintain an online diary, to customize the look and feel of the site and generally helps you interact with the site more efficiently.

    To create an account, simply fill out this form an click the `Register' button below. An e-mail will then be sent to you with instructions on how to validate your account.

    \n"; + + $output .= "\n"; + $output .= "

    \n"; + $output .= " Username:
    \n"; + $output .= "
    \n"; + $output .= " Enter your desired username: only letters, numbers and some special characters are allowed.
    \n"; + $output .= "

    \n"; + $output .= "

    \n"; + $output .= " E-mail address:
    \n"; + $output .= "
    \n"; + $output .= " You will be sent instructions on how to validate your account via this e-mail address - please make sure it is accurate.
    \n"; + $output .= "

    \n"; + $output .= "

    \n"; + $output .= " \n"; + $output .= "

    \n"; $output .= "
    \n"; $theme->header(); @@ -270,24 +275,62 @@ function account_new($user = "", $error = "") { $theme->footer(); } -function account_validate($user) { - include "includes/ban.inc"; +function account_register_submit($new) { + global $theme, $mail, $sitename; - ### Verify username and e-mail address: - $user[userid] = trim($user[userid]); - if (empty($user[email]) || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $user[email]))) $rval = "the specified e-mail address is not valid.
    "; - if (empty($user[userid]) || (ereg("[^a-zA-Z0-9_-]", $user[userid]))) $rval = "the specified username '$new[userid]' is not valid.
    "; - if (strlen($user[userid]) > 15) $rval = "the specified username is too long: it must be less than 15 characters."; + if ($rval = account_validate($new)) { + account_register_enter($new, "$rval"); + } + else { + $new[passwd] = account_password(); + $new[status] = 1; + $new[hash] = substr(md5("$new[userid]. ". time() .""), 0, 12); - ### Check to see whether the username or e-mail address are banned: - if ($ban = ban_match($user[userid], $type2index[usernames])) $rval = "the specified username is banned for the following reason: $ban->reason."; - if ($ban = ban_match($user[email], $type2index[addresses])) $rval = "the specified e-mail address is banned for the following reason: $ban->reason."; + user_save($new); - ### Verify whether username and e-mail address are unique: - if (db_num_rows(db_query("SELECT userid FROM users WHERE LOWER(userid)=LOWER('$user[userid]')")) > 0) $rval = "the specified username is already taken."; - if (db_num_rows(db_query("SELECT email FROM users WHERE LOWER(email)=LOWER('$user[email]')")) > 0) $rval = "the specified e-mail address is already registered."; + $link = "http://". getenv("HOSTNAME") ."/account.php?op=confirm&name=$new[userid]&hash=$new[hash]"; + $message = "$new[userid],\n\n\nsomeone signed up for a user account on $sitename and supplied this email address as their contact. If it wasn't you, don't get your panties in a knot and simply ignore this mail.\n\nIf this was you, you have to activate your account first before you can login. You can activate your account by visiting the URL below:\n\n $link\n\nVisiting this URL will automatically activate your account. Once activated you can login using the following information:\n\n username: $new[userid]\n password: $new[passwd]\n\n\n-- $sitename crew\n"; + // mail($new[real_email], "Account details for $sitename", $message, "From: noreply@$sitename"); + print "
    $message
    \n"; + + watchdog(1, "new user `$new[userid]' <$new[real_email]>"); - return($rval); + $theme->header(); + $theme->box("Account details", "Congratulations! Your member account has been sucessfully created and further instructions on how to activate your account have been sent to your e-mail address."); + $theme->footer(); + } +} + +function account_register_confirm($name, $hash) { + global $theme; + + $result = db_query("SELECT userid, hash, status FROM users WHERE userid = '$name'"); + + if ($account = db_fetch_object($result)) { + if ($account->status == 1) { + if ($account->hash == $hash) { + db_query("UPDATE users SET status = 2, hash = '' WHERE userid = '$name'"); + $output .= "Your account has been sucessfully confirmed. You can click here to login.\n"; + watchdog(1, "$name: account confirmation sucessful"); + } + else { + $output .= "Confirmation failed: invalid confirmation hash.\n"; + watchdog(3, "$name: invalid confirmation hash"); + } + } + else { + $output .= "Confirmation failed: your account has already been confirmed. You can click here to login.\n"; + watchdog(3, "$name: attempt to re-confirm account"); + } + } + else { + $output .= "Confirmation failed: no such account found.
    "; + watchdog(3, "$name: attempt to confirm non-existing account"); + } + + $theme->header(); + $theme->box("Account confirmation", $output); + $theme->footer(); } function account_password($min_length=6) { @@ -300,9 +343,8 @@ function account_password($min_length=6) { function account_comments() { global $theme, $user; - $output .= "

    This page might be helpful in case you want to keep track of your most recent comments in any of the discussions. You are given an overview of your comments in each of the stories you participates in along with the number of replies each comment got.\n

    \n"; + $info = "

    This page might be helpful in case you want to keep track of your most recent comments in any of the discussions. You are given an overview of your comments in each of the stories you participates in along with the number of replies each comment got.\n

    \n"; - ### Perform query: $sresult = db_query("SELECT s.id, s.subject, COUNT(s.id) as count FROM comments c LEFT JOIN stories s ON c.sid = s.id WHERE c.author = $user->id GROUP BY s.id DESC LIMIT 5"); while ($story = db_fetch_object($sresult)) { @@ -315,7 +357,9 @@ function account_comments() { } $output .= " \n"; } - + + $output = ($output) ? "$info $output" : "$info

    You have not posted any comments recently.
    \n"; + $theme->header(); $theme->box("Track your comments", $output); $theme->footer(); @@ -326,8 +370,14 @@ switch ($op) { account_session_start($userid, $passwd); header("Location: account.php?op=info"); break; - case "new": - account_new(); + case "register": + account_register_enter(); + break; + case "confirm": + account_register_confirm($name, $hash); + break; + case "Register": + account_register_submit($new); break; case "view": account_user($name); @@ -343,7 +393,7 @@ switch ($op) { header("Location: account.php"); break; case "Register": - account_register($new); + account_register_submit($new); break; case "user": account_user_edit(); diff --git a/admin.php b/admin.php index 9cc637d6b..05737b1c6 100644 --- a/admin.php +++ b/admin.php @@ -8,7 +8,7 @@ if ($user->userid != "Dries") exit(); */ function account_display($order = "username") { - $sort = array("ID" => "id", "fake e-mail address" => "femail", "homepage" => "url", "hostname" => "last_host", "last access date" => "last_access", "real e-mail address" => "email", "real name" => "name", "status" => "status", "theme" => "theme", "username" => "userid"); + $sort = array("ID" => "id", "fake e-mail address" => "fake_email", "homepage" => "url", "hostname" => "last_host", "last access date" => "last_access", "real e-mail address" => "real_email", "real name" => "name", "status" => "status", "theme" => "theme", "username" => "userid"); $show = array("ID" => "id", "username" => "userid", "$order" => "$sort[$order]", "status" => "status"); ### Perform query: @@ -39,7 +39,7 @@ function account_display($order = "username") { $output .= " \n"; foreach ($show as $key=>$value) { switch($value) { - case "email": + case "real_email": $output .= " ". format_email_address($account[$value]) ."\n"; break; case "last_access": @@ -91,8 +91,8 @@ function account_view($name) { $output .= " ID:$account->id\n"; $output .= " Username:$account->userid\n"; $output .= " Real name:". format_data($account->name) ."\n"; - $output .= " Real e-mail address:". format_email_address($account->email) ."\n"; - $output .= " Fake e-mail address:". format_data($account->femail) ."\n"; + $output .= " Real e-mail address:". format_email_address($account->real_email) ."\n"; + $output .= " Fake e-mail address:". format_data($account->fake_email) ."\n"; $output .= " URL of homepage:". format_url($account->url) ."\n"; $output .= " Last access:". format_date($account->last_access) ." from $account->last_host\n"; $output .= " Bio information:". format_data($account->bio) ."\n"; @@ -110,10 +110,10 @@ function account_view($name) { */ function log_display($order = "date") { $colors = array("#FFFFFF", "#FFFFFF", "#90EE90", "#CD5C5C"); - $fields = array("date" => "id DESC", "username" => "user", "message" => "message DESC", "level" => "level DESC"); + $fields = array("date" => "id DESC", "username" => "user", "location" => "location", "message" => "message DESC", "level" => "level DESC"); ### Perform query: - $result = db_query("SELECT l.*, u.userid FROM logs l LEFT JOIN users u ON l.user = u.id ORDER BY l.$fields[$order]"); + $result = db_query("SELECT l.*, u.userid FROM watchdog l LEFT JOIN users u ON l.user = u.id ORDER BY l.$fields[$order]"); ### Generate output: $output .= "\n"; @@ -146,13 +146,14 @@ function log_display($order = "date") { } function log_view($id) { - $result = db_query("SELECT l.*, u.userid FROM logs l LEFT JOIN users u ON l.user = u.id WHERE l.id = $id"); + $result = db_query("SELECT l.*, u.userid FROM watchdog l LEFT JOIN users u ON l.user = u.id WHERE l.id = $id"); if ($log = db_fetch_object($result)) { $output .= "
    \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; + $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
    Level:$log->level
    Date:". format_date($log->timestamp, "extra large") ."
    User:". format_username($log->userid, 1) ."
    Location:$log->location
    Message:$log->message
    Hostname:$log->hostname
    \n"; @@ -557,7 +558,6 @@ function info_display() { $output .= "sitename: $sitename
    \n"; $output .= "e-mail address: $contact_email
    \n"; - $output .= "signature: $contact_signature
    \n"; $output .= "send e-mail notifications: $notify
    \n"; $output .= "allowed HTML tags: ". htmlspecialchars($allowed_html) ."
    \n"; $output .= "anonymous user: $anonymous
    \n"; diff --git a/diary.php b/diary.php index 24addc434..7fdf0801e 100644 --- a/diary.php +++ b/diary.php @@ -66,7 +66,6 @@ function diary_display($username) { function diary_add() { global $theme, $user, $allowed_html; - ### Submission form: $output .= "
    \n"; $output .= "

    \n"; diff --git a/discussion.php b/discussion.php index 1a06b0426..a6097b4d8 100644 --- a/discussion.php +++ b/discussion.php @@ -23,33 +23,33 @@ function discussion_moderate($moderate) { } } -function discussion_kids($cid, $mode, $thold, $level = 0, $dummy = 0) { +function discussion_kids($cid, $mode, $threshold, $level = 0, $dummy = 0) { global $user, $theme; $comments = 0; - $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid AND (c.votes = 0 OR c.score / c.votes >= $thold) ORDER BY c.timestamp, c.cid"); + $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid AND (c.votes = 0 OR c.score / c.votes >= $threshold) ORDER BY c.timestamp, c.cid"); if ($mode == "nested") { while ($comment = db_fetch_object($result)) { - if ($comment->score >= $thold) { + if ($comment->score >= $threshold) { if ($level && !$comments) print "