mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
new permission: user-delete + user-change-class
This commit is contained in:
+3
-21
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user