Allow for setting an account's inactivity status

This adds a field to the users table and corresponding fields to the
account edit and display forms that allow for setting an (in-)activity
status.

This might turn out to be useful if a user is on vacation and can not
respond to update/orphan/deletion requests.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2013-08-04 14:19:32 +02:00
parent 6ecfe12ce2
commit 6844f6c1d2
6 changed files with 46 additions and 8 deletions

View file

@ -1,6 +1,15 @@
Upgrading Upgrading
========= =========
From 2.2.0 to 2.3.0
-------------------
1. Add an inactivity time stamp to the "Users" table:
----
ALTER TABLE Users ADD COLUMN InactivityTS BIGINT NOT NULL DEFAULT 0;
----
From 2.1.0 to 2.2.0 From 2.1.0 to 2.2.0
------------------- -------------------

View file

@ -35,6 +35,7 @@ CREATE TABLE Users (
LastVoted BIGINT UNSIGNED NOT NULL DEFAULT 0, LastVoted BIGINT UNSIGNED NOT NULL DEFAULT 0,
LastLogin BIGINT UNSIGNED NOT NULL DEFAULT 0, LastLogin BIGINT UNSIGNED NOT NULL DEFAULT 0,
LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0, LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0,
InactivityTS BIGINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (ID), PRIMARY KEY (ID),
UNIQUE (Username), UNIQUE (Username),
UNIQUE (Email), UNIQUE (Email),

View file

@ -52,7 +52,8 @@ if (isset($_COOKIE["AURSID"])) {
display_account_form($atype, "UpdateAccount", $row["Username"], display_account_form($atype, "UpdateAccount", $row["Username"],
$row["AccountTypeID"], $row["Suspended"], $row["Email"], $row["AccountTypeID"], $row["Suspended"], $row["Email"],
"", "", $row["RealName"], $row["LangPreference"], "", "", $row["RealName"], $row["LangPreference"],
$row["IRCNick"], $row["PGPKey"], $row["ID"]); $row["IRCNick"], $row["PGPKey"],
$row["InactivityTS"] ? 1 : 0, $row["ID"]);
} else { } else {
print __("You do not have permission to edit this account."); print __("You do not have permission to edit this account.");
} }
@ -81,7 +82,7 @@ if (isset($_COOKIE["AURSID"])) {
in_request("U"), in_request("T"), in_request("S"), in_request("U"), in_request("T"), in_request("S"),
in_request("E"), in_request("P"), in_request("C"), in_request("E"), in_request("P"), in_request("C"),
in_request("R"), in_request("L"), in_request("I"), in_request("R"), in_request("L"), in_request("I"),
in_request("K"), in_request("ID")); in_request("K"), in_request("J"), in_request("ID"));
} }
} else { } else {
if ($atype == "Trusted User" || $atype == "Developer") { if ($atype == "Trusted User" || $atype == "Developer") {

View file

@ -54,12 +54,13 @@ function html_format_pgp_fingerprint($fingerprint) {
* @param string $L The language preference of the displayed user * @param string $L The language preference of the displayed user
* @param string $I The IRC nickname of the displayed user * @param string $I The IRC nickname of the displayed user
* @param string $K The PGP key fingerprint of the displayed user * @param string $K The PGP key fingerprint of the displayed user
* @param string $J The inactivity status of the displayed user
* @param string $UID The user ID of the displayed user * @param string $UID The user ID of the displayed user
* *
* @return void * @return void
*/ */
function display_account_form($UTYPE,$A,$U="",$T="",$S="", function display_account_form($UTYPE,$A,$U="",$T="",$S="",
$E="",$P="",$C="",$R="",$L="",$I="",$K="",$UID=0) { $E="",$P="",$C="",$R="",$L="",$I="",$K="",$J="", $UID=0) {
global $SUPPORTED_LANGS; global $SUPPORTED_LANGS;
include("account_edit_form.php"); include("account_edit_form.php");
@ -83,12 +84,13 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
* @param string $L The language preference of the user * @param string $L The language preference of the user
* @param string $I The IRC nickname of the user * @param string $I The IRC nickname of the user
* @param string $K The PGP fingerprint of the user * @param string $K The PGP fingerprint of the user
* @param string $J The inactivity status of the user
* @param string $UID The user ID of the modified account * @param string $UID The user ID of the modified account
* *
* @return string|void Return void if successful, otherwise return error * @return string|void Return void if successful, otherwise return error
*/ */
function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
$P="",$C="",$R="",$L="",$I="",$K="",$UID=0) { $P="",$C="",$R="",$L="",$I="",$K="",$J="",$UID=0) {
# error check and process request for a new/modified account # error check and process request for a new/modified account
global $SUPPORTED_LANGS, $AUR_LOCATION; global $SUPPORTED_LANGS, $AUR_LOCATION;
@ -185,7 +187,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
if ($error) { if ($error) {
print "<ul class='errorlist'><li>".$error."</li></ul>\n"; print "<ul class='errorlist'><li>".$error."</li></ul>\n";
display_account_form($UTYPE, $A, $U, $T, $S, $E, "", "", display_account_form($UTYPE, $A, $U, $T, $S, $E, "", "",
$R, $L, $I, $K, $UID); $R, $L, $I, $K, $J, $UID);
} else { } else {
if ($TYPE == "new") { if ($TYPE == "new") {
# no errors, go ahead and create the unprivileged user # no errors, go ahead and create the unprivileged user
@ -206,9 +208,10 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
$I = $dbh->quote($I); $I = $dbh->quote($I);
$K = $dbh->quote(str_replace(" ", "", $K)); $K = $dbh->quote(str_replace(" ", "", $K));
$q = "INSERT INTO Users (AccountTypeID, Suspended, "; $q = "INSERT INTO Users (AccountTypeID, Suspended, ";
$q.= "Username, Email, Passwd, Salt, RealName, "; $q.= "InactivityTS, Username, Email, Passwd, Salt, ";
$q.= "LangPreference, IRCNick, PGPKey) VALUES (1, 0, "; $q.= "RealName, LangPreference, IRCNick, PGPKey) ";
$q.= "$U, $E, $P, $salt, $R, $L, $I, $K)"; $q.= "VALUES (1, 0, 0, $U, $E, $P, $salt, $R, $L, ";
$q.= "$I, $K)";
$result = $dbh->exec($q); $result = $dbh->exec($q);
if (!$result) { if (!$result) {
print __("Error trying to create account, %s%s%s.", print __("Error trying to create account, %s%s%s.",
@ -240,6 +243,18 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
} else { } else {
# no errors, go ahead and modify the user account # no errors, go ahead and modify the user account
$q = "SELECT InactivityTS FROM Users WHERE ";
$q.= "ID = " . intval($UID);
$result = $dbh->query($q);
$row = $result->fetch(PDO::FETCH_NUM);
if ($row[0] && $J) {
$inactivity_ts = $row[0];
} elseif ($J) {
$inactivity_ts = time();
} else {
$inactivity_ts = 0;
}
$q = "UPDATE Users SET "; $q = "UPDATE Users SET ";
$q.= "Username = " . $dbh->quote($U); $q.= "Username = " . $dbh->quote($U);
if ($T) { if ($T) {
@ -262,6 +277,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
$q.= ", LangPreference = " . $dbh->quote($L); $q.= ", LangPreference = " . $dbh->quote($L);
$q.= ", IRCNick = " . $dbh->quote($I); $q.= ", IRCNick = " . $dbh->quote($I);
$q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K));
$q.= ", InactivityTS = " . $inactivity_ts;
$q.= " WHERE ID = ".intval($UID); $q.= " WHERE ID = ".intval($UID);
$result = $dbh->exec($q); $result = $dbh->exec($q);
if (!$result) { if (!$result) {

View file

@ -37,6 +37,12 @@
<th><?= __("PGP Key Fingerprint") . ":" ?></th> <th><?= __("PGP Key Fingerprint") . ":" ?></th>
<td><?= html_format_pgp_fingerprint($row["PGPKey"]) ?></td> <td><?= html_format_pgp_fingerprint($row["PGPKey"]) ?></td>
</tr> </tr>
<tr>
<th><?= __("Status") . ":" ?></th>
<td>
<?= $row["InactivityTS"] ? __("Inactive since") . ' ' . date("Y-m-d H:i", $row["InactivityTS"]) : __("Active"); ?>
</td>
</tr>
<tr> <tr>
<th><?= __("Last Voted") . ":" ?></th> <th><?= __("Last Voted") . ":" ?></th>
<td> <td>

View file

@ -55,6 +55,11 @@
</p> </p>
<?php endif; ?> <?php endif; ?>
<p>
<label for="id_inactive"><?= __("Inactive") ?>:</label>
<input type="checkbox" name="J" id="id_inactive" <?= $J ? 'checked="checked"' : '' ?> />
</p>
<p> <p>
<label for="id_email"><?= __("Email Address") ?>:</label> <label for="id_email"><?= __("Email Address") ?>:</label>
<input type="text" size="30" maxlength="64" name="E" id="id_email" value="<?= htmlspecialchars($E,ENT_QUOTES) ?>" /> (<?= __("required") ?>) <input type="text" size="30" maxlength="64" name="E" id="id_email" value="<?= htmlspecialchars($E,ENT_QUOTES) ?>" /> (<?= __("required") ?>)