3 namespace BookStack\Console\Commands;
5 use BookStack\Users\Models\User;
6 use Illuminate\Console\Command;
8 class ResetMfa extends Command
11 * The name and signature of the console command.
15 protected $signature = 'bookstack:reset-mfa
16 {--id= : Numeric ID of the user to reset MFA for}
17 {--email= : Email address of the user to reset MFA for}
21 * The console command description.
25 protected $description = 'Reset & Clear any configured MFA methods for the given user';
28 * Create a new command instance.
32 public function __construct()
34 parent::__construct();
38 * Execute the console command.
42 public function handle()
44 $id = $this->option('id');
45 $email = $this->option('email');
46 if (!$id && !$email) {
47 $this->error('Either a --id=<number> or --email=<email> option must be provided.');
52 $field = $id ? 'id' : 'email';
53 $value = $id ?: $email;
55 /** @var User $user */
57 ->where($field, '=', $value)
61 $this->error("A user where {$field}={$value} could not be found.");
66 $this->info("This will delete any configure multi-factor authentication methods for user: \n- ID: {$user->id}\n- Name: {$user->name}\n- Email: {$user->email}\n");
67 $this->info('If multi-factor authentication is required for this user they will be asked to reconfigure their methods on next login.');
68 $confirm = $this->confirm('Are you sure you want to proceed?');
70 $user->mfaValues()->delete();
71 $this->info('User MFA methods have been reset.');