diff options
Diffstat (limited to 'web/lib/acctfuncs.inc.php')
-rw-r--r-- | web/lib/acctfuncs.inc.php | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 9bd6e511..512e66ce 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -35,7 +35,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="", print "<input type='hidden' name='ID' value='".$UID."' />\n"; } print "</fieldset>"; - print "<table border='0' cellpadding='0' cellspacing='0' width='80%' style=\"margin:0 auto;\">\n"; + print "<table>\n"; print "<tr><td colspan='2'> </td></tr>\n"; print "<tr>"; @@ -171,14 +171,15 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", # error check and process request for a new/modified account global $SUPPORTED_LANGS; + $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."); @@ -196,7 +197,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 ) @@ -233,7 +234,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>"); } } @@ -251,7 +252,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>"); } } @@ -273,12 +274,12 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", "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."); @@ -310,10 +311,10 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", $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>"); } } @@ -415,13 +416,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", } 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 "<table class='results'>\n"; print "<tr>"; print "<th class='header'>"; print "<span class='f2'>".__("Username")."</span></th>"; @@ -466,7 +461,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", print "</span></td>"; print "<td class='".$c."'><span class='f5'>"; $row["LastVoted"] - ? print date("Ymd", $row["LastVoted"]) + ? print date("Y-m-d", $row["LastVoted"]) : print __("Never"); print "</span></td>"; print "<td class='".$c."'><span class='f5'>"; @@ -483,8 +478,8 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", $i++; } print "</table>\n"; - print "</td></tr>\n"; + print "<table class='results'>\n"; print "<tr>"; print "<td align='left'>"; print "<form action='account.php' method='post'>\n"; @@ -531,16 +526,17 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="", # Display non-editable account info # -function display_account_info($U="", $T="", $E="", $R="", $I="") { +function display_account_info($U="", $T="", $E="", $R="", $I="", $LV="") { # 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 + # LV: value to display for last voted global $SUPPORTED_LANGS; - print "<table border='0' cellpadding='0' cellspacing='0' width='33%' style=\"margin:0 auto;\">\n"; + print "<table>\n"; print " <tr>\n"; print " <td colspan='2'> </td>\n"; print " </tr>\n"; @@ -579,6 +575,13 @@ function display_account_info($U="", $T="", $E="", $R="", $I="") { print " </tr>\n"; print " <tr>\n"; + print " <td align='left'>".__("Last Voted").":</td>\n"; + print " <td align='left'>"; + print $LV ? date("Y-m-d", $LV) : __("Never"); + print "</td>\n"; + print " </tr>\n"; + + print " <tr>\n"; print " <td colspan='2'><a href='packages.php?K=".$U."&SeB=m'>".__("View this user's packages")."</a></td>\n"; print " </tr>\n"; @@ -598,21 +601,20 @@ function try_login() { $userID = null; if ( isset($_REQUEST['user']) || isset($_REQUEST['passwd']) ) { + $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 @@ -643,8 +645,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. @@ -710,11 +715,10 @@ 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 ) { /* if ( $user = valid_username($user) ) { */ if ( $user ) { - $dbh = db_connect(); $q = "SELECT ID FROM Users WHERE Username = '" . db_escape_string($user). "'"; @@ -739,11 +743,9 @@ function good_passwd( $passwd ) /* Verifies that the password is correct for the userID specified. * Returns true or false */ -function valid_passwd( $userID, $passwd ) +function valid_passwd( $userID, $passwd, $dbh ) { if ( strlen($passwd) > 0 ) { - $dbh = db_connect(); - # get salt for this user $salt = get_salt($userID); if ($salt) { @@ -784,12 +786,11 @@ function valid_passwd( $userID, $passwd ) /* * Is the user account suspended? */ -function user_suspended( $id ) +function user_suspended( $id, $dbh ) { if (!$id) { return false; } - $dbh = db_connect(); $q = "SELECT Suspended FROM Users WHERE ID = " . $id; $result = db_query($q, $dbh); if ($result) { @@ -804,9 +805,8 @@ function user_suspended( $id ) /* * This should be expanded to return something */ -function user_delete( $id ) +function user_delete( $id, $dbh ) { - $dbh = db_connect(); $q = "DELETE FROM Users WHERE ID = " . $id; db_query($q, $dbh); return; @@ -816,9 +816,8 @@ function user_delete( $id ) * A different way of determining a user's privileges * rather than account_from_sid() */ -function user_is_privileged( $id ) +function user_is_privileged( $id, $dbh ) { - $dbh = db_connect(); $q = "SELECT AccountTypeID FROM Users WHERE ID = " . $id; $result = db_query($q, $dbh); if ($result) { @@ -832,13 +831,9 @@ function user_is_privileged( $id ) } # Clear out old expired sessions. -function clear_expired_sessions($dbh = null) { +function clear_expired_sessions( $dbh ) { global $LOGIN_TIMEOUT; - if (empty($dbh)) { - $dbh = db_connect(); - } - $q = "DELETE FROM Sessions WHERE LastUpdateTS < (UNIX_TIMESTAMP() - $LOGIN_TIMEOUT)"; db_query($q, $dbh); |