summaryrefslogtreecommitdiffstats
path: root/web/lib/acctfuncs.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib/acctfuncs.inc.php')
-rw-r--r--web/lib/acctfuncs.inc.php661
1 files changed, 325 insertions, 336 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index b7c3ee8..a41a4e7 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -8,10 +8,28 @@ function in_request($name) {
return "";
}
+# Format PGP key fingerprint
+function html_format_pgp_fingerprint($fingerprint) {
+ if (strlen($fingerprint) != 40 || !ctype_xdigit($fingerprint)) {
+ return $fingerprint;
+ }
+
+ return htmlspecialchars(substr($fingerprint, 0, 4) . " " .
+ substr($fingerprint, 4, 4) . " " .
+ substr($fingerprint, 8, 4) . " " .
+ substr($fingerprint, 12, 4) . " " .
+ substr($fingerprint, 16, 4) . " " .
+ substr($fingerprint, 20, 4) . " " .
+ substr($fingerprint, 24, 4) . " " .
+ substr($fingerprint, 28, 4) . " " .
+ substr($fingerprint, 32, 4) . " " .
+ substr($fingerprint, 36, 4) . " ", ENT_QUOTES);
+}
+
# Display the standard Account form, pass in default values if any
function display_account_form($UTYPE,$A,$U="",$T="",$S="",
- $E="",$P="",$C="",$R="",$L="",$I="",$UID=0) {
+ $E="",$P="",$C="",$R="",$L="",$I="",$K="",$UID=0) {
# UTYPE: what user type the form is being displayed for
# A: what "form" name to use
# U: value to display for username
@@ -28,124 +46,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
global $SUPPORTED_LANGS;
- print "<form action='account.php' method='post'>\n";
- print "<fieldset>";
- print "<input type='hidden' name='Action' value='".$A."' />\n";
- if ($UID) {
- print "<input type='hidden' name='ID' value='".$UID."' />\n";
- print "<input type='hidden' name='token' value='".htmlspecialchars($_COOKIE['AURSID'])."' />\n";
- }
- print "</fieldset>";
- print "<table border='0' cellpadding='0' cellspacing='0' width='80%' style=\"margin:0 auto;\">\n";
- print "<tr><td colspan='2'>&nbsp;</td></tr>\n";
-
- print "<tr>";
- print "<td align='left'>".__("Username").":</td>";
- print "<td align='left'><input type='text' size='30' maxlength='64'";
- print " name='U' value='".htmlspecialchars($U,ENT_QUOTES)."' /> (".__("required").")</td>";
- print "</tr>\n";
-
- # Only TUs or Devs can promote/demote/suspend a user
- if ($UTYPE == "Trusted User" || $UTYPE == "Developer") {
- print "<tr>";
- print "<td align='left'>".__("Account Type").":</td>";
- print "<td align='left'><select name=T>\n";
- print "<option value='1'";
- $T == "User" ? print " selected>" : print ">";
- print __("Normal user")."\n";
- print "<option value='2'";
- $T == "Trusted User" ? print " selected>" : print ">";
- print __("Trusted user")."\n";
-
- # Only developers can make another account a developer
- if ($UTYPE == "Developer") {
- print "<option value='3'";
- $T == "Developer" ? print " selected>" : print ">";
- print __("Developer")."\n";
- }
- print "</select></td>";
- print "</tr>\n";
-
- print "<tr>";
- print "<td align='left'>".__("Account Suspended").":</td>";
- print "<td align='left'><input type='checkbox' name='S'";
- if ($S) {
- print " checked=\"checked\" />";
- } else {
- print " />";
- }
- print "</tr>\n";
- }
-
- print "<tr>";
- print "<td align='left'>".__("Email Address").":</td>";
- print "<td align='left'><input type='text' size='30' maxlength='64'";
- print " name='E' value='".htmlspecialchars($E,ENT_QUOTES)."' /> (".__("required").")</td>";
- print "</tr>\n";
-
- print "<tr>";
- print "<td align='left'>".__("Password").":</td>";
- print "<td align='left'><input type='password' size='30' maxlength='32'";
- print " name='P' value='".$P."' />";
- if ($A != "UpdateAccount") {
- print " (".__("required").")";
- }
- print "</td></tr>\n";
-
- print "<tr>";
- print "<td align='left'>".__("Re-type password").":</td>";
- print "<td align='left'><input type='password' size='30' maxlength='32'";
- print " name='C' value='".$C."' />";
- if ($A != "UpdateAccount") {
- print " (".__("required").")";
- }
- print "</td></tr>\n";
-
- print "<tr>";
- print "<td align='left'>".__("Real Name").":</td>";
- print "<td align='left'><input type='text' size='30' maxlength='32'";
- print " name='R' value='".htmlspecialchars($R,ENT_QUOTES)."' /></td>";
- print "</tr>\n";
-
- print "<tr>";
- print "<td align='left'>".__("IRC Nick").":</td>";
- print "<td align='left'><input type='text' size='30' maxlength='32'";
- print " name='I' value='".htmlspecialchars($I,ENT_QUOTES)."' /></td>";
- print "</tr>\n";
-
- print "<tr>";
- print "<td align='left'>".__("Language").":</td>";
- print "<td align='left'><select name=L>\n";
-
- reset($SUPPORTED_LANGS);
- while (list($code, $lang) = each($SUPPORTED_LANGS)) {
- if ($L == $code) {
- print "<option value=".$code." selected> ".$lang."\n";
- } else {
- print "<option value=".$code."> ".$lang."\n";
- }
- }
- print "</select></td>";
- print "</tr>\n";
-
- print "<tr><td colspan='2'>&nbsp;</td></tr>\n";
- print "<tr>";
- print "<td>&nbsp;</td>";
- print "<td align='left'>";
-
- if ($A == "UpdateAccount") {
- print "<input type='submit' class='button'";
- print " value='".__("Update")."' /> &nbsp; ";
- } else {
- print "<input type='submit' class='button'";
- print " value='".__("Create")."' /> &nbsp; ";
- }
- print "<input type='reset' class='button' value='".__("Reset")."' />";
- print "</td>";
- print "</tr>\n";
-
- print "</table>\n";
- print "</form>\n";
+ include("account_edit_form.php");
return;
} # function display_account_form()
@@ -153,7 +54,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
# process form input from a new/edit account form
#
function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
- $P="",$C="",$R="",$L="",$I="",$UID=0) {
+ $P="",$C="",$R="",$L="",$I="",$K="",$UID=0,$dbh=NULL) {
# UTYPE: The user's account type
# TYPE: either "edit" or "new"
# A: what parent "form" name to use
@@ -172,14 +73,17 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
# error check and process request for a new/modified account
global $SUPPORTED_LANGS;
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
if(isset($_COOKIE['AURSID'])) {
- $editor_user = uid_from_sid($_COOKIE['AURSID']);
+ $editor_user = uid_from_sid($_COOKIE['AURSID'], $dbh);
}
else {
$editor_user = null;
}
- $dbh = db_connect();
$error = "";
if (empty($E) || empty($U)) {
$error = __("Missing a required field.");
@@ -197,7 +101,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
}
}
- if (!$error && !valid_username($U) && !user_is_privileged($editor_user))
+ if (!$error && !valid_username($U) && !user_is_privileged($editor_user, $dbh))
$error = __("The username is invalid.") . "<ul>\n"
."<li>" . __("It must be between %s and %s characters long",
USERNAME_MIN_LEN, USERNAME_MAX_LEN )
@@ -215,6 +119,11 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
if (!$error && !valid_email($E)) {
$error = __("The email address is invalid.");
}
+
+ if (!$error && $K != '' && !valid_pgp_fingerprint($K)) {
+ $error = __("The PGP key fingerprint is invalid.");
+ }
+
if ($UTYPE == "Trusted User" && $T == 3) {
$error = __("A Trusted User cannot assign Developer status.");
}
@@ -234,7 +143,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
if ($result) {
$row = mysql_fetch_array($result);
if ($row[0]) {
- $error = __("The username, %h%s%h, is already in use.",
+ $error = __("The username, %s%s%s, is already in use.",
"<b>", htmlspecialchars($U,ENT_QUOTES), "</b>");
}
}
@@ -252,7 +161,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
if ($result) {
$row = mysql_fetch_array($result);
if ($row[0]) {
- $error = __("The address, %h%s%h, is already in use.",
+ $error = __("The address, %s%s%s, is already in use.",
"<b>", htmlspecialchars($E,ENT_QUOTES), "</b>");
}
}
@@ -260,26 +169,26 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
if ($error) {
print "<span class='error'>".$error."</span><br/>\n";
display_account_form($UTYPE, $A, $U, $T, $S, $E, "", "",
- $R, $L, $I, $UID);
+ $R, $L, $I, $K, $UID);
} else {
if ($TYPE == "new") {
# no errors, go ahead and create the unprivileged user
$salt = generate_salt();
$P = salted_hash($P, $salt);
$escaped = array_map('db_escape_string',
- array($U, $E, $P, $salt, $R, $L, $I));
+ array($U, $E, $P, $salt, $R, $L, $I, str_replace(" ", "", $K)));
$q = "INSERT INTO Users (" .
"AccountTypeID, Suspended, Username, Email, Passwd, Salt" .
- ", RealName, LangPreference, IRCNick) " .
+ ", RealName, LangPreference, IRCNick, PGPKey) " .
"VALUES (1, 0, '" . implode("', '", $escaped) . "')";
$result = db_query($q, $dbh);
if (!$result) {
- print __("Error trying to create account, %h%s%h: %s.",
+ print __("Error trying to create account, %s%s%s: %s.",
"<b>", htmlspecialchars($U,ENT_QUOTES), "</b>", mysql_error($dbh));
} else {
# account created/modified, tell them so.
#
- print __("The account, %h%s%h, has been successfully created.",
+ print __("The account, %s%s%s, has been successfully created.",
"<b>", htmlspecialchars($U,ENT_QUOTES), "</b>");
print "<p>\n";
print __("Click on the Home link above to login.");
@@ -308,13 +217,14 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
$q.= ", RealName = '".db_escape_string($R)."'";
$q.= ", LangPreference = '".db_escape_string($L)."'";
$q.= ", IRCNick = '".db_escape_string($I)."'";
+ $q.= ", PGPKey = '".db_escape_string(str_replace(" ", "", $K))."'";
$q.= " WHERE ID = ".intval($UID);
$result = db_query($q, $dbh);
if (!$result) {
- print __("Error trying to modify account, %h%s%h: %s.",
+ print __("Error trying to modify account, %s%s%s: %s.",
"<b>", htmlspecialchars($U,ENT_QUOTES), "</b>", mysql_error($dbh));
} else {
- print __("The account, %h%s%h, has been successfully modified.",
+ print __("The account, %s%s%s, has been successfully modified.",
"<b>", htmlspecialchars($U,ENT_QUOTES), "</b>");
}
}
@@ -333,7 +243,7 @@ function search_accounts_form() {
# search results page
#
function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
- $S="",$E="",$R="",$I="") {
+ $S="",$E="",$R="",$I="",$K="",$dbh=NULL) {
# UTYPE: what account type the user belongs to
# O: what row offset we're at
# SB: how to sort the results
@@ -388,6 +298,10 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
$q.= "AND IRCNick LIKE '%".db_escape_like($I)."%' ";
$search_vars[] = "I";
}
+ if ($K) {
+ $q.= "AND PGPKey LIKE '%".db_escape_like(str_replace(" ", "", $K))."%' ";
+ $search_vars[] = "K";
+ }
switch ($SB) {
case 't':
$q.= "ORDER BY AccountTypeID, Username ";
@@ -408,182 +322,18 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
$search_vars[] = "SB";
$q.= "LIMIT " . $HITS_PER_PAGE . " OFFSET " . $OFFSET;
- $dbh = db_connect();
-
- $result = db_query($q, $dbh);
- if (!$result) {
- print __("No results matched your search criteria.");
- } else {
- $num_rows = mysql_num_rows($result);
- if ($num_rows) {
- print "<table border='0' cellpadding='0'";
- print " cellspacing='0' width='90%'";
- print " style=\"margin:0 auto\">\n";
- print "<tr>";
- print "<td colspan='2'>";
- print "<table border='0' cellpadding='0'";
- print " cellspacing='0' width='100%'>\n";
- print "<tr>";
- print "<th class='header'>";
- print "<span class='f2'>".__("Username")."</span></th>";
- print "<th class='header'>";
- print "<span class='f2'>".__("Type")."</span></th>";
- print "<th class='header'>";
- print "<span class='f2'>".__("Status")."</span></th>";
- print "<th class='header'>";
- print "<span class='f2'>".__("Real Name")."</span></th>";
- print "<th class='header'>";
- print "<span class='f2'>".__("IRC Nick")."</span></th>";
- print "<th class='header'>";
- print "<span class='f2'>".__("Last Voted")."</span></th>";
- print "<th class='header'>";
- print "<span class='f2'>".__("Edit Account")."</span></th>";
- print "</tr>\n";
- $i = 0;
- while ($row = mysql_fetch_assoc($result)) {
- if ($i % 2) {
- $c = "data1";
- } else {
- $c = "data2";
- }
- print "<tr>";
- print "<td class='".$c."'>";
- print "<span class='f5'><a href='packages.php?SeB=m&amp;K=".$row["Username"]."'>".$row["Username"]."</a></span></td>";
- print "<td class='".$c."'>";
- print "<span class='f5'>".$row["AccountType"];
- print "</span></td>";
- print "<td class='".$c."'><span class='f5'>";
- if ($row["Suspended"]) {
- print __("Suspended");
- } else {
- print __("Active");
- }
- print "</span></td>";
- print "<td class='".$c."'><span class='f5'>";
- $row["RealName"] ? print htmlspecialchars($row["RealName"],ENT_QUOTES) : print "&nbsp;";
- print "</span></td>";
- print "<td class='".$c."'><span class='f5'>";
- $row["IRCNick"] ? print htmlspecialchars($row["IRCNick"],ENT_QUOTES) : print "&nbsp;";
- print "</span></td>";
- print "<td class='".$c."'><span class='f5'>";
- $row["LastVoted"]
- ? print date("Ymd", $row["LastVoted"])
- : print __("Never");
- print "</span></td>";
- print "<td class='".$c."'><span class='f5'>";
- if ($UTYPE == "Trusted User" && $row["AccountType"] == "Developer") {
- # TUs can't edit devs
- #
- print "&nbsp;</span></td>";
- } else {
- $edit_url = "account.php?Action=DisplayAccount&amp;ID=".$row["ID"];
- print "<a href='".$edit_url . "'>";
- print "Edit</a></span></td>";
- }
- print "</tr>\n";
- $i++;
- }
- print "</table>\n";
- print "</td></tr>\n";
-
- print "<tr>";
- print "<td align='left'>";
- print "<form action='account.php' method='post'>\n";
- print "<fieldset>";
- print "<input type='hidden' name='Action' value='SearchAccounts' />\n";
- print "<input type='hidden' name='O'";
- print " value='".($OFFSET-$HITS_PER_PAGE)."' />\n";
- reset($search_vars);
- while (list($k, $ind) = each($search_vars)) {
- print "<input type='hidden' name='".$ind."'";
- print " value='".${$ind}."' />\n";
- }
- print "<input type='submit' class='button'";
- print " value='&lt;-- ".__("Less")."' />";
- print "</fieldset>";
- print "</form>\n";
- print "</td>";
- print "<td align='right'>";
- print "<form action='account.php' method='post'>\n";
- print "<fieldset>";
- print "<input type='hidden' name='Action' value='SearchAccounts' />\n";
- print "<input type='hidden' name='O'";
- print " value='".($OFFSET+$HITS_PER_PAGE)."' />\n";
- reset($search_vars);
- while (list($k, $ind) = each($search_vars)) {
- print "<input type='hidden' name='".$ind."'";
- print " value='".${$ind}."' />\n";
- }
- print "<input type='submit' class='button'";
- print " value='".__("More")." --&gt;' />";
- print "</fieldset>";
- print "</form>\n";
- print "</td>";
- print "</tr>\n";
- print "</table>\n";
- } else {
- print "<p style=\"text-align:center;\">\n";
- print __("No more results to display.");
- print "</p>\n";
- }
+ if (!$dbh) {
+ $dbh = db_connect();
}
- return;
-}
-# Display non-editable account info
-#
-function display_account_info($U="", $T="", $E="", $R="", $I="") {
- # U: value to display for username
- # T: value to display for account type
- # E: value to display for email address
- # R: value to display for RealName
- # I: value to display for IRC nick
+ $result = db_query($q, $dbh);
+ $num_rows = mysql_num_rows($result);
- global $SUPPORTED_LANGS;
+ while ($row = mysql_fetch_assoc($result)) {
+ $userinfo[] = $row;
+ }
- print "<table border='0' cellpadding='0' cellspacing='0' width='33%' style=\"margin:0 auto;\">\n";
- print " <tr>\n";
- print " <td colspan='2'>&nbsp;</td>\n";
- print " </tr>\n";
-
- print " <tr>\n";
- print " <td align='left'>".__("Username").":</td>\n";
- print " <td align='left'>".$U."</td>\n";
- print " </tr>\n";
-
- print " <tr>\n";
- print " <td align='left'>".__("Account Type").":</td>\n";
- print " <td align='left'>";
- if ($T == "User") {
- print __("User");
- } elseif ($T == "Trusted User") {
- print __("Trusted User");
- } elseif ($T == "Developer") {
- print __("Developer");
- }
- print " </td>\n";
- print " </tr>\n";
-
- print " <tr>\n";
- print " <td align='left'>".__("Email Address").":</td>\n";
- print " <td align='left'><a href='mailto:".htmlspecialchars($E,ENT_QUOTES)."'>".htmlspecialchars($E,ENT_QUOTES)."</a></td>\n";
- print " </tr>\n";
-
- print " <tr>\n";
- print " <td align='left'>".__("Real Name").":</td>\n";
- print " <td align='left'>".htmlspecialchars($R,ENT_QUOTES)."</td>\n";
- print " </tr>\n";
-
- print " <tr>\n";
- print " <td align='left'>".__("IRC Nick").":</td>\n";
- print " <td align='left'>".htmlspecialchars($I,ENT_QUOTES)."</td>\n";
- print " </tr>\n";
-
- print " <tr>\n";
- print " <td colspan='2'><a href='packages.php?K=".$U."&amp;SeB=m'>".__("View this user's packages")."</a></td>\n";
- print " </tr>\n";
-
- print "</table>\n";
+ include("account_search_results.php");
return;
}
@@ -591,7 +341,7 @@ function display_account_info($U="", $T="", $E="", $R="", $I="") {
* Returns SID (Session ID) and error (error message) in an array
* SID of 0 means login failed.
*/
-function try_login() {
+function try_login($dbh=NULL) {
global $MAX_SESSIONS_PER_USER, $PERSISTENT_COOKIE_TIMEOUT;
$login_error = "";
@@ -599,21 +349,22 @@ function try_login() {
$userID = null;
if ( isset($_REQUEST['user']) || isset($_REQUEST['passwd']) ) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+ $userID = valid_user($_REQUEST['user'], $dbh);
- $userID = valid_user($_REQUEST['user']);
-
- if ( user_suspended( $userID ) ) {
+ if ( user_suspended($userID, $dbh) ) {
$login_error = "Account Suspended.";
}
elseif ( $userID && isset($_REQUEST['passwd'])
- && valid_passwd($userID, $_REQUEST['passwd']) ) {
+ && valid_passwd($userID, $_REQUEST['passwd'], $dbh) ) {
$logged_in = 0;
$num_tries = 0;
# Account looks good. Generate a SID and store it.
- $dbh = db_connect();
while (!$logged_in && $num_tries < 5) {
if ($MAX_SESSIONS_PER_USER) {
# Delete all user sessions except the
@@ -644,8 +395,11 @@ function try_login() {
}
if ($logged_in) {
- # set our SID cookie
+ $q = "UPDATE Users SET LastLogin = UNIX_TIMESTAMP() ";
+ $q.= "WHERE ID = '$userID'";
+ db_query($q, $dbh);
+ # set our SID cookie
if (isset($_POST['remember_me']) &&
$_POST['remember_me'] == "on") {
# Set cookies for 30 days.
@@ -684,8 +438,7 @@ function try_login() {
* Returns the username if it is valid
* Returns nothing if it isn't valid
*/
-function valid_username( $user )
-{
+function valid_username($user) {
if (!empty($user)) {
#Is username at not too short or too long?
@@ -711,11 +464,14 @@ function valid_username( $user )
* Checks if the username is valid and if it exists in the database
* Returns the username ID or nothing
*/
-function valid_user( $user )
-{
+function valid_user($user, $dbh=NULL) {
/* if ( $user = valid_username($user) ) { */
- if ( $user ) {
+
+ if(!$dbh) {
$dbh = db_connect();
+ }
+
+ if ( $user ) {
$q = "SELECT ID FROM Users WHERE Username = '"
. db_escape_string($user). "'";
@@ -729,8 +485,72 @@ function valid_user( $user )
return;
}
-function good_passwd( $passwd )
-{
+# Check for any open proposals about a user. Used to prevent multiple proposals.
+function open_user_proposals($user, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "SELECT * FROM TU_VoteInfo WHERE User = '" . db_escape_string($user) . "'";
+ $q.= " AND End > UNIX_TIMESTAMP()";
+ $result = db_query($q, $dbh);
+ if (mysql_num_rows($result)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+# Creates a new trusted user proposal from entered agenda.
+# Optionally takes proposal about specific user. Length of vote set by submitter.
+function add_tu_proposal($agenda, $user, $votelength, $submitteruid, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, SubmitterID) VALUES ";
+ $q.= "('" . db_escape_string($agenda) . "', ";
+ $q.= "'" . db_escape_string($user) . "', ";
+ $q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . db_escape_string($votelength);
+ $q.= ", " . $submitteruid . ")";
+ db_query($q, $dbh);
+
+}
+
+# Add a reset key for a specific user
+function create_resetkey($resetkey, $uid, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "UPDATE Users ";
+ $q.= "SET ResetKey = '" . $resetkey . "' ";
+ $q.= "WHERE ID = " . $uid;
+ db_query($q, $dbh);
+}
+
+# Change a password and save the salt only if reset key and email are correct
+function password_reset($hash, $salt, $resetkey, $email, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "UPDATE Users ";
+ $q.= "SET Passwd = '$hash', ";
+ $q.= "Salt = '$salt', ";
+ $q.= "ResetKey = '' ";
+ $q.= "WHERE ResetKey != '' ";
+ $q.= "AND ResetKey = '".db_escape_string($resetkey)."' ";
+ $q.= "AND Email = '".db_escape_string($email)."'";
+ $result = db_query($q, $dbh);
+
+ if (!mysql_affected_rows($dbh)) {
+ $error = __('Invalid e-mail and reset key combination.');
+ return $error;
+ } else {
+ header('Location: passreset.php?step=complete');
+ exit();
+ }
+}
+
+function good_passwd($passwd) {
if ( strlen($passwd) >= PASSWD_MIN_LEN ) {
return true;
}
@@ -740,11 +560,11 @@ function good_passwd( $passwd )
/* Verifies that the password is correct for the userID specified.
* Returns true or false
*/
-function valid_passwd( $userID, $passwd )
-{
- if ( strlen($passwd) > 0 ) {
+function valid_passwd($userID, $passwd, $dbh=NULL) {
+ if (!$dbh) {
$dbh = db_connect();
-
+ }
+ if ( strlen($passwd) > 0 ) {
# get salt for this user
$salt = get_salt($userID);
if ($salt) {
@@ -783,14 +603,23 @@ function valid_passwd( $userID, $passwd )
}
/*
+ * Checks if the PGP key fingerprint is valid (must be 40 hexadecimal digits).
+ */
+function valid_pgp_fingerprint($fingerprint) {
+ $fingerprint = str_replace(" ", "", $fingerprint);
+ return (strlen($fingerprint) == 40 && ctype_xdigit($fingerprint));
+}
+
+/*
* Is the user account suspended?
*/
-function user_suspended( $id )
-{
+function user_suspended($id, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
if (!$id) {
return false;
}
- $dbh = db_connect();
$q = "SELECT Suspended FROM Users WHERE ID = " . $id;
$result = db_query($q, $dbh);
if ($result) {
@@ -805,9 +634,10 @@ function user_suspended( $id )
/*
* This should be expanded to return something
*/
-function user_delete( $id )
-{
- $dbh = db_connect();
+function user_delete($id, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
$q = "DELETE FROM Users WHERE ID = " . $id;
db_query($q, $dbh);
return;
@@ -817,26 +647,38 @@ function user_delete( $id )
* A different way of determining a user's privileges
* rather than account_from_sid()
*/
-function user_is_privileged( $id )
-{
- $dbh = db_connect();
+function user_is_privileged($id, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
$q = "SELECT AccountTypeID FROM Users WHERE ID = " . $id;
$result = db_query($q, $dbh);
if ($result) {
$row = mysql_fetch_row($result);
- if( $result[0] > 1) {
- return $result[0];
+ if($row[0] > 1) {
+ return $row[0];
}
}
return 0;
}
+# Remove session on logout
+function delete_session_id($sid, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "DELETE FROM Sessions WHERE SessionID = '";
+ $q.= db_escape_string($sid) . "'";
+ db_query($q, $dbh);
+}
+
# Clear out old expired sessions.
-function clear_expired_sessions($dbh = null) {
+function clear_expired_sessions($dbh=NULL) {
global $LOGIN_TIMEOUT;
- if (empty($dbh)) {
+ if(!$dbh) {
$dbh = db_connect();
}
@@ -846,3 +688,150 @@ function clear_expired_sessions($dbh = null) {
return;
}
+function account_details($uid, $username, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "SELECT Users.*, AccountTypes.AccountType ";
+ $q.= "FROM Users, AccountTypes ";
+ $q.= "WHERE AccountTypes.ID = Users.AccountTypeID ";
+ if (!empty($uid)) {
+ $q.= "AND Users.ID = ".intval($uid);
+ } else {
+ $q.= "AND Users.Username = '".db_escape_string($username) . "'";
+ }
+ $result = db_query($q, $dbh);
+
+ if ($result) {
+ $row = mysql_fetch_assoc($result);
+ }
+
+ return $row;
+}
+
+function own_account_details($sid, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "SELECT Users.*, AccountTypes.AccountType ";
+ $q.= "FROM Users, AccountTypes, Sessions ";
+ $q.= "WHERE AccountTypes.ID = Users.AccountTypeID ";
+ $q.= "AND Users.ID = Sessions.UsersID ";
+ $q.= "AND Sessions.SessionID = '";
+ $q.= db_escape_string($sid)."'";
+ $result = db_query($q, $dbh);
+
+ if ($result) {
+ $row = mysql_fetch_assoc($result);
+ }
+
+ return $row;
+}
+
+function tu_voted($voteid, $uid, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "SELECT * FROM TU_Votes WHERE VoteID = " . intval($voteid) . " AND UserID = " . intval($uid);
+ $result = db_query($q, $dbh);
+ if (mysql_num_rows($result)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+function current_proposal_list($order, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "SELECT * FROM TU_VoteInfo WHERE End > " . time() . " ORDER BY Submitted " . $order;
+ $result = db_query($q, $dbh);
+
+ $details = array();
+ while ($row = mysql_fetch_assoc($result)) {
+ $details[] = $row;
+ }
+
+ return $details;
+}
+
+function past_proposal_list($order, $lim, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "SELECT * FROM TU_VoteInfo WHERE End < " . time() . " ORDER BY Submitted " . $order . $lim;
+ $result = db_query($q, $dbh);
+
+ $details = array();
+ while ($row = mysql_fetch_assoc($result)) {
+ $details[] = $row;
+ }
+
+ return $details;
+}
+
+function proposal_count($dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "SELECT COUNT(*) FROM TU_VoteInfo";
+ $result = db_query($q, $dbh);
+ $row = mysql_fetch_row($result);
+
+ return $row[0];
+}
+
+function vote_details($voteid, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "SELECT * FROM TU_VoteInfo ";
+ $q.= "WHERE ID = " . intval($voteid);
+
+ $result = db_query($q, $dbh);
+ $row = mysql_fetch_assoc($result);
+
+ return $row;
+}
+
+function voter_list($voteid, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $whovoted = '';
+
+ $q = "SELECT tv.UserID,U.Username ";
+ $q.= "FROM TU_Votes tv, Users U ";
+ $q.= "WHERE tv.VoteID = " . intval($voteid);
+ $q.= " AND tv.UserID = U.ID ";
+ $q.= "ORDER BY Username";
+
+ $result = db_query($q, $dbh);
+ if ($result) {
+ while ($row = mysql_fetch_assoc($result)) {
+ $whovoted.= '<a href="account.php?Action=AccountInfo&amp;ID='.$row['UserID'].'">'.$row['Username'].'</a> ';
+ }
+ }
+ return $whovoted;
+}
+
+function cast_proposal_vote($voteid, $uid, $vote, $newtotal, $dbh=NULL) {
+ if (!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "UPDATE TU_VoteInfo SET " . $vote . " = " . ($newtotal) . " WHERE ID = " . $voteid;
+ db_query($q, $dbh);
+
+ $q = "INSERT INTO TU_Votes (VoteID, UserID) VALUES (" . $voteid . ", " . $uid . ")";
+ db_query($q, $dbh);
+
+}