From cdb4a9b38eee4393b2463d51a4b5bde06d173024 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 1 Mar 2019 14:02:34 -0700 Subject: [PATCH] Add user:delete command --- app/Console/Commands/UserDelete.php | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/Console/Commands/UserDelete.php diff --git a/app/Console/Commands/UserDelete.php b/app/Console/Commands/UserDelete.php new file mode 100644 index 000000000..a11c7d750 --- /dev/null +++ b/app/Console/Commands/UserDelete.php @@ -0,0 +1,72 @@ +argument('id'); + $user = User::whereUsername($id)->orWhere('id', $id)->first(); + if(!$user) { + $this->error('Could not find any user with that username or id.'); + exit; + } + + if($user->is_admin == true) { + $this->error('Cannot delete an admin account from CLI.'); + exit; + } + + if(!$this->confirm('Are you sure you want to delete this account?')) { + exit; + } + + $confirmation = $this->ask('Enter the username to confirm deletion'); + + if($confirmation !== $user->username) { + $this->error('Username does not match, exiting...'); + exit; + } + + $profile = $user->profile; + $profile->status = $user->status = 'deleted'; + $profile->save(); + $user->save(); + + DeleteAccountPipeline::dispatchNow($user); + } +}