]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/ResetMfaCommand.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Console / Commands / ResetMfaCommand.php
1 <?php
2
3 namespace BookStack\Console\Commands;
4
5 use Exception;
6 use Illuminate\Console\Command;
7
8 class ResetMfaCommand extends Command
9 {
10     use HandlesSingleUser;
11
12     /**
13      * The name and signature of the console command.
14      *
15      * @var string
16      */
17     protected $signature = 'bookstack:reset-mfa
18                             {--id= : Numeric ID of the user to reset MFA for}
19                             {--email= : Email address of the user to reset MFA for} 
20                             ';
21
22     /**
23      * The console command description.
24      *
25      * @var string
26      */
27     protected $description = 'Reset & Clear any configured MFA methods for the given user';
28
29     /**
30      * Execute the console command.
31      */
32     public function handle(): int
33     {
34         try {
35             $user = $this->fetchProvidedUser();
36         } catch (Exception $exception) {
37             $this->error($exception->getMessage());
38             return 1;
39         }
40
41         $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");
42         $this->info('If multi-factor authentication is required for this user they will be asked to reconfigure their methods on next login.');
43         $confirm = $this->confirm('Are you sure you want to proceed?');
44         if (!$confirm) {
45             return 1;
46         }
47
48         $user->mfaValues()->delete();
49         $this->info('User MFA methods have been reset.');
50
51         return 0;
52     }
53 }