Flag users as disabled/deleted if they can't actually be deleted
This commit is contained in:
parent
e607c120c4
commit
207be7114a
@ -52,7 +52,8 @@ switch ($VARS['action']) {
|
|||||||
'realname' => $VARS['name'],
|
'realname' => $VARS['name'],
|
||||||
'username' => $VARS['username'],
|
'username' => $VARS['username'],
|
||||||
'email' => $VARS['email'],
|
'email' => $VARS['email'],
|
||||||
'acctstatus' => $VARS['status']
|
'acctstatus' => $VARS['status'],
|
||||||
|
'deleted' => 0
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!is_empty($VARS['pass'])) {
|
if (!is_empty($VARS['pass'])) {
|
||||||
@ -78,6 +79,11 @@ switch ($VARS['action']) {
|
|||||||
}
|
}
|
||||||
$olddata = $database->select('accounts', '*', ['uid' => $VARS['id']])[0];
|
$olddata = $database->select('accounts', '*', ['uid' => $VARS['id']])[0];
|
||||||
$database->delete('accounts', ['uid' => $VARS['id']]);
|
$database->delete('accounts', ['uid' => $VARS['id']]);
|
||||||
|
if (!is_null($database->error()[1])) {
|
||||||
|
// If we can't delete the account (because it's referenced elsewhere),
|
||||||
|
// we will flag it as deleted and set the status to LOCKED_OR_DISABLED.
|
||||||
|
$database->update('accounts', ['acctstatus' => 2, 'deleted' => 1], ['uid' => $VARS['id']]);
|
||||||
|
}
|
||||||
insertAuthLog(16, $_SESSION['uid'], $olddata['username'] . ", " . $olddata['realname'] . ", " . $olddata['email'] . ", " . $olddata['acctstatus']);
|
insertAuthLog(16, $_SESSION['uid'], $olddata['username'] . ", " . $olddata['realname'] . ", " . $olddata['email'] . ", " . $olddata['acctstatus']);
|
||||||
returnToSender("user_deleted");
|
returnToSender("user_deleted");
|
||||||
case "rmtotp":
|
case "rmtotp":
|
||||||
|
@ -85,5 +85,7 @@ define("STRINGS", [
|
|||||||
"remove 2fa" => "Reset 2FA",
|
"remove 2fa" => "Reset 2FA",
|
||||||
"action performed by" => "Action performed by {user}",
|
"action performed by" => "Action performed by {user}",
|
||||||
"2fa removed" => "2-factor authentication removed.",
|
"2fa removed" => "2-factor authentication removed.",
|
||||||
"2fa" => "2FA"
|
"2fa" => "2FA",
|
||||||
|
"show deleted" => "Show deleted",
|
||||||
|
"editing deleted account" => "You are editing an account marked as deleted. The account will be undeleted if you press Save."
|
||||||
]);
|
]);
|
@ -6,11 +6,20 @@ dieifnotloggedin();
|
|||||||
|
|
||||||
header("Content-Type: application/json");
|
header("Content-Type: application/json");
|
||||||
|
|
||||||
|
$show_deleted = false;
|
||||||
|
if ($VARS['show_deleted'] == 1) {
|
||||||
|
$show_deleted = true;
|
||||||
|
}
|
||||||
|
|
||||||
$out = [];
|
$out = [];
|
||||||
|
|
||||||
$out['draw'] = intval($VARS['draw']);
|
$out['draw'] = intval($VARS['draw']);
|
||||||
|
|
||||||
$out['recordsTotal'] = $database->count('accounts');
|
if ($show_deleted) {
|
||||||
|
$out['recordsTotal'] = $database->count('accounts');
|
||||||
|
} else {
|
||||||
|
$out['recordsTotal'] = $database->count('accounts', ['deleted' => 0]);
|
||||||
|
}
|
||||||
$filter = false;
|
$filter = false;
|
||||||
|
|
||||||
// sort
|
// sort
|
||||||
@ -43,6 +52,7 @@ switch ($VARS['order'][0]['column']) {
|
|||||||
// search
|
// search
|
||||||
if (!is_empty($VARS['search']['value'])) {
|
if (!is_empty($VARS['search']['value'])) {
|
||||||
$filter = true;
|
$filter = true;
|
||||||
|
if ($show_deleted) {
|
||||||
$wherenolimit = [
|
$wherenolimit = [
|
||||||
"OR" => [
|
"OR" => [
|
||||||
"username[~]" => $VARS['search']['value'],
|
"username[~]" => $VARS['search']['value'],
|
||||||
@ -52,10 +62,27 @@ if (!is_empty($VARS['search']['value'])) {
|
|||||||
"typecode[~]" => $VARS['search']['value']
|
"typecode[~]" => $VARS['search']['value']
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
} else {
|
||||||
|
$wherenolimit = [
|
||||||
|
"AND" => [
|
||||||
|
"OR" => [
|
||||||
|
"username[~]" => $VARS['search']['value'],
|
||||||
|
"realname[~]" => $VARS['search']['value'],
|
||||||
|
"email[~]" => $VARS['search']['value'],
|
||||||
|
"statuscode[~]" => $VARS['search']['value'],
|
||||||
|
"typecode[~]" => $VARS['search']['value']
|
||||||
|
],
|
||||||
|
"deleted" => 0
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
$where = $wherenolimit;
|
$where = $wherenolimit;
|
||||||
$where["LIMIT"] = [$VARS['start'], $VARS['length']];
|
$where["LIMIT"] = [$VARS['start'], $VARS['length']];
|
||||||
} else {
|
} else {
|
||||||
$where = ["LIMIT" => [$VARS['start'], $VARS['length']]];
|
$where = ["LIMIT" => [$VARS['start'], $VARS['length']]];
|
||||||
|
if (!$show_deleted) {
|
||||||
|
$where["deleted"] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!is_null($order)) {
|
if (!is_null($order)) {
|
||||||
$where["ORDER"] = $order;
|
$where["ORDER"] = $order;
|
||||||
@ -74,7 +101,8 @@ $users = $database->select('accounts', [
|
|||||||
'acctstatus',
|
'acctstatus',
|
||||||
'statuscode',
|
'statuscode',
|
||||||
'accttype',
|
'accttype',
|
||||||
'typecode'
|
'typecode',
|
||||||
|
'deleted'
|
||||||
], $where);
|
], $where);
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ $userdata = [
|
|||||||
'email' => '',
|
'email' => '',
|
||||||
'authsecret' => '',
|
'authsecret' => '',
|
||||||
'acctstatus' => '',
|
'acctstatus' => '',
|
||||||
'typecode' => 'LOCAL'
|
'typecode' => 'LOCAL',
|
||||||
|
'deleted' => 0
|
||||||
];
|
];
|
||||||
|
|
||||||
$editing = false;
|
$editing = false;
|
||||||
@ -27,7 +28,8 @@ if (!is_empty($VARS['id'])) {
|
|||||||
'email',
|
'email',
|
||||||
'authsecret',
|
'authsecret',
|
||||||
'acctstatus',
|
'acctstatus',
|
||||||
'typecode'
|
'typecode',
|
||||||
|
'deleted'
|
||||||
], [
|
], [
|
||||||
'uid' => $VARS['id']
|
'uid' => $VARS['id']
|
||||||
])[0];
|
])[0];
|
||||||
@ -70,6 +72,13 @@ if ($userdata['typecode'] != "LOCAL") {
|
|||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
if ($userdata['deleted'] == 1) {
|
||||||
|
?>
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<?php lang("editing deleted account"); ?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name"><i class="fa fa-user"></i> <?php lang("name"); ?></label>
|
<label for="name"><i class="fa fa-user"></i> <?php lang("name"); ?></label>
|
||||||
@ -80,7 +89,7 @@ if ($userdata['typecode'] != "LOCAL") {
|
|||||||
<div class="col-xs-12 col-md-6">
|
<div class="col-xs-12 col-md-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username"><i class="fa fa-id-badge"></i> <?php lang("username"); ?></label>
|
<label for="username"><i class="fa fa-id-badge"></i> <?php lang("username"); ?></label>
|
||||||
<input type="text" <?php if (!$localacct) echo "disabled"; ?> class="form-control" name="username" id="username" placeholder="<?php lang("placeholder username"); ?>" required="required" value="<?php echo htmlspecialchars($userdata['username']); ?>" />
|
<input type="text" <?php if (!$localacct) echo "readonly=\"readonly\""; ?> class="form-control" name="username" id="username" placeholder="<?php lang("placeholder username"); ?>" required="required" value="<?php echo htmlspecialchars($userdata['username']); ?>" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-12 col-md-6">
|
<div class="col-xs-12 col-md-6">
|
||||||
@ -95,7 +104,7 @@ if ($userdata['typecode'] != "LOCAL") {
|
|||||||
<div class="col-xs-12 col-md-6">
|
<div class="col-xs-12 col-md-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="pass"><i class="fa fa-lock"></i> <?php lang("new password"); ?></label>
|
<label for="pass"><i class="fa fa-lock"></i> <?php lang("new password"); ?></label>
|
||||||
<input type="text" <?php if (!$localacct) echo "disabled"; ?> autocomplete="new-password" class="form-control" name="pass" id="pass" placeholder="<?php lang("placeholder password"); ?>" />
|
<input type="text" <?php if (!$localacct) echo "readonly=\"readonly\""; ?> autocomplete="new-password" class="form-control" name="pass" id="pass" placeholder="<?php lang("placeholder password"); ?>" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ redirectifnotloggedin();
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
/*$users = $database->select('accounts', [
|
/* $users = $database->select('accounts', [
|
||||||
"[>]acctstatus" => ['acctstatus' => 'statusid'],
|
"[>]acctstatus" => ['acctstatus' => 'statusid'],
|
||||||
"[>]accttypes" => ['accttype' => 'typeid']
|
"[>]accttypes" => ['accttype' => 'typeid']
|
||||||
], [
|
], [
|
||||||
@ -48,7 +48,7 @@ redirectifnotloggedin();
|
|||||||
<td><?php echo $u['typecode']; ?></td>
|
<td><?php echo $u['typecode']; ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
}*/
|
} */
|
||||||
?>
|
?>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
@ -63,3 +63,9 @@ redirectifnotloggedin();
|
|||||||
<th data-priority="4"><i class="fa fa-fw fa-server"></i> <?php lang('type'); ?></th>
|
<th data-priority="4"><i class="fa fa-fw fa-server"></i> <?php lang('type'); ?></th>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
<script>
|
||||||
|
/* Give JavaScript access to the lang string
|
||||||
|
* it needs to inject the show deleted checkbox
|
||||||
|
*/
|
||||||
|
var lang_show_deleted = "<?php lang("show deleted") ?>";
|
||||||
|
</script>
|
@ -1,4 +1,4 @@
|
|||||||
$('#usertable').DataTable({
|
var usertable = $('#usertable').DataTable({
|
||||||
responsive: {
|
responsive: {
|
||||||
details: {
|
details: {
|
||||||
display: $.fn.dataTable.Responsive.display.modal({
|
display: $.fn.dataTable.Responsive.display.modal({
|
||||||
@ -30,6 +30,11 @@ $('#usertable').DataTable({
|
|||||||
serverSide: true,
|
serverSide: true,
|
||||||
ajax: {
|
ajax: {
|
||||||
url: "lib/getusertable.php",
|
url: "lib/getusertable.php",
|
||||||
|
data: function (d) {
|
||||||
|
if ($('#show_deleted_checkbox').is(':checked')) {
|
||||||
|
d.show_deleted = 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
dataFilter: function (data) {
|
dataFilter: function (data) {
|
||||||
var json = jQuery.parseJSON(data);
|
var json = jQuery.parseJSON(data);
|
||||||
json.data = [];
|
json.data = [];
|
||||||
@ -37,8 +42,8 @@ $('#usertable').DataTable({
|
|||||||
json.data.push([
|
json.data.push([
|
||||||
"",
|
"",
|
||||||
row.editbtn,
|
row.editbtn,
|
||||||
row.realname,
|
(row.deleted == 1 ? "<del style=\"color: red;\">" : "") + row.realname + (row.deleted == 1 ? "</del>" : ""),
|
||||||
row.username,
|
(row.deleted == 1 ? "<span style=\"color: red;\">" : "") + row.username + (row.deleted == 1 ? "</span>" : ""),
|
||||||
row.email,
|
row.email,
|
||||||
(row['2fa'] == true ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>"),
|
(row['2fa'] == true ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>"),
|
||||||
row.statuscode,
|
row.statuscode,
|
||||||
@ -49,3 +54,5 @@ $('#usertable').DataTable({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#usertable_filter').append("<div class=\"checkbox\" style=\"display: inline-block\"><label><input type=\"checkbox\" id=\"show_deleted_checkbox\" onclick=\"usertable.ajax.reload()\"> " + lang_show_deleted + "</label></div>");
|
Loading…
x
Reference in New Issue
Block a user