From 6c82b8afb54c6470418657f01859adbbcb42c40e Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 13 Sep 2022 19:32:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E5=B0=81=E7=A6=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/BanUser.php | 72 ++++++++++++++++++++ app/Console/Commands/SuspendUserAllHosts.php | 52 ++++++++++++++ app/Console/Kernel.php | 4 ++ 3 files changed, 128 insertions(+) create mode 100644 app/Console/Commands/BanUser.php create mode 100644 app/Console/Commands/SuspendUserAllHosts.php diff --git a/app/Console/Commands/BanUser.php b/app/Console/Commands/BanUser.php new file mode 100644 index 0000000..129527e --- /dev/null +++ b/app/Console/Commands/BanUser.php @@ -0,0 +1,72 @@ +argument('user_id'); + + $reason = $this->argument('reason'); + + $user = User::find($user_id); + + $this->info('封禁: ' . $user->name); + + $this->confirm('确定要继续吗?如果继续,将会暂停所有的 Host。'); + + $user->banned_at = now(); + $user->banned_reason = $reason; + $user->save(); + + $this->info('正在暂停所有的 Host...'); + Host::where('user_id', $user_id)->update([ + 'status' => 'suspended', + 'suspended_at' => now() + ]); + + $this->info('正在清除 Token.'); + + AccessToken::where('user_id', $user_id)->delete(); + + $this->info('封禁用户成功。'); + + } +} diff --git a/app/Console/Commands/SuspendUserAllHosts.php b/app/Console/Commands/SuspendUserAllHosts.php new file mode 100644 index 0000000..2afcef5 --- /dev/null +++ b/app/Console/Commands/SuspendUserAllHosts.php @@ -0,0 +1,52 @@ +argument('user_id'); + + Host::where('user_id', $user_id)->update([ + 'status' => 'suspended', + 'suspended_at' => now() + ]); + + $this->info('暂停用户的所有 Host 成功。'); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index b5de5fc..02754c5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,6 +2,8 @@ namespace App\Console; +use App\Console\Commands\BanUser; +use App\Console\Commands\SuspendUserAllHosts; use App\Jobs\HostCost; use App\Jobs\ClearTasks; use App\Jobs\DeleteHost; @@ -18,6 +20,8 @@ class Kernel extends ConsoleKernel */ protected $commands = [ // + BanUser::class, + SuspendUserAllHosts::class ]; /**