2021-07-14 15:50:36 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2023-09-19 10:53:01 -04:00
|
|
|
use Exception;
|
2021-07-14 15:50:36 -04:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
2023-05-24 08:21:46 -04:00
|
|
|
class ResetMfaCommand extends Command
|
2021-07-14 15:50:36 -04:00
|
|
|
{
|
2023-09-19 10:53:01 -04:00
|
|
|
use HandlesSingleUser;
|
|
|
|
|
2021-07-14 15:50:36 -04:00
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'bookstack:reset-mfa
|
|
|
|
{--id= : Numeric ID of the user to reset MFA for}
|
|
|
|
{--email= : Email address of the user to reset MFA for}
|
|
|
|
';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Reset & Clear any configured MFA methods for the given user';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
2023-05-24 07:59:50 -04:00
|
|
|
public function handle(): int
|
2021-07-14 15:50:36 -04:00
|
|
|
{
|
2023-09-19 10:53:01 -04:00
|
|
|
try {
|
|
|
|
$user = $this->fetchProvidedUser();
|
|
|
|
} catch (Exception $exception) {
|
|
|
|
$this->error($exception->getMessage());
|
2021-07-14 15:50:36 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$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");
|
|
|
|
$this->info('If multi-factor authentication is required for this user they will be asked to reconfigure their methods on next login.');
|
|
|
|
$confirm = $this->confirm('Are you sure you want to proceed?');
|
2023-05-24 07:59:50 -04:00
|
|
|
if (!$confirm) {
|
|
|
|
return 1;
|
2021-07-14 15:50:36 -04:00
|
|
|
}
|
|
|
|
|
2023-05-24 07:59:50 -04:00
|
|
|
$user->mfaValues()->delete();
|
|
|
|
$this->info('User MFA methods have been reset.');
|
|
|
|
|
|
|
|
return 0;
|
2021-07-14 15:50:36 -04:00
|
|
|
}
|
|
|
|
}
|