My beer compendium
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

3 years ago
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\User;
  5. use App\Jobs\DeletePipeline\DeleteAccountPipeline;
  6. class UserDelete extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'user:delete {id} {--force}';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Delete account';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $id = $this->argument('id');
  37. $force = $this->option('force');
  38. if(ctype_digit($id) == true) {
  39. $user = User::find($id);
  40. } else {
  41. $user = User::whereUsername($id)->first();
  42. }
  43. if(!$user) {
  44. $this->error('Could not find any user with that username or id.');
  45. exit;
  46. }
  47. if($user->is_admin == true) {
  48. $this->error('Cannot delete an admin account from CLI.');
  49. exit;
  50. }
  51. if(!$this->confirm('Are you sure you want to delete this account?')) {
  52. exit;
  53. }
  54. $confirmation = $this->ask('Enter the username to confirm deletion');
  55. if($confirmation !== $user->username) {
  56. $this->error('Username does not match, exiting...');
  57. exit;
  58. }
  59. $user->delete();
  60. $this->error('User deleted');
  61. }
  62. }