new permission: user-delete + user-change-class

This commit is contained in:
xiaomlove
2022-09-13 04:09:23 +08:00
parent 9a00c17ea5
commit 7a435132d6
10 changed files with 70 additions and 39 deletions
+3 -21
View File
@@ -1,8 +1,7 @@
<?php
require "../include/bittorrent.php";
dbconn();
if (get_user_class() < UC_ADMINISTRATOR)
stderr("Error", "Permission denied.");
user_can('user-delete', true);
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
@@ -18,25 +17,8 @@ $arr = mysql_fetch_assoc($res);
$id = $arr['id'];
$name = $arr['username'];
try {
\Nexus\Database\NexusDB::transaction(function () use ($id) {
$affectedRows = \Nexus\Database\NexusDB::table('users')->where('id', $id)->delete();
if ($affectedRows != 1) {
throw new \RuntimeException("Unable to delete the account.");
}
$tables = [
'hit_and_runs' => 'uid',
'claims' => 'uid',
'exam_users' => 'uid',
'exam_progress' => 'uid',
];
foreach ($tables as $table => $key) {
\Nexus\Database\NexusDB::table($table)->where($key, $id)->delete();
}
});
} catch (\Exception $exception) {
stderr("Error", $exception->getMessage());
}
$userRep = new \App\Repositories\UserRepository();
$userRep->destroy($id);
stderr("Success", "The account <b>".htmlspecialchars($name)."</b> was deleted.",false);
}
stdhead("Delete account");