38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace IriksIT\Manager\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use IriksIT\Manager\Support\TwoFactor\Authenticator;
|
|
|
|
/**
|
|
* Takes the second step away from an account that lost its phone and its recovery codes, for the one who cannot log in (the last super admin). The account
|
|
* sets it up again at its next login; its grace period is not given back.
|
|
*
|
|
* php artisan manager:two-factor-reset [email protected]
|
|
*/
|
|
class TwoFactorResetCommand extends Command
|
|
{
|
|
protected $signature = 'manager:two-factor-reset {email : The email address of the account}';
|
|
|
|
protected $description = 'Take the second step of login away from an account that lost its phone';
|
|
|
|
public function handle(Authenticator $authenticator): int
|
|
{
|
|
$model = config('manager.user_model');
|
|
$user = $model::query()->where('email', strtolower((string) $this->argument('email')))->first();
|
|
|
|
if ($user === null) {
|
|
$this->error('There is no account with that email address.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$authenticator->reset($user);
|
|
$authenticator->log('two_factor.reset', 'The second step was reset from the command line', null, $user);
|
|
$this->info('The second step of '.$user->email.' is off. It sets it up again at the next login.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|