X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/4c726201f94fe5c80de7e9a83e210d210c49c86f..refs/pull/5689/head:/app/Console/Commands/ResetMfaCommand.php diff --git a/app/Console/Commands/ResetMfaCommand.php b/app/Console/Commands/ResetMfaCommand.php index b8076d2d6..2b0801e39 100644 --- a/app/Console/Commands/ResetMfaCommand.php +++ b/app/Console/Commands/ResetMfaCommand.php @@ -2,11 +2,13 @@ namespace BookStack\Console\Commands; -use BookStack\Users\Models\User; +use Exception; use Illuminate\Console\Command; class ResetMfaCommand extends Command { + use HandlesSingleUser; + /** * The name and signature of the console command. * @@ -29,25 +31,10 @@ class ResetMfaCommand extends Command */ public function handle(): int { - $id = $this->option('id'); - $email = $this->option('email'); - if (!$id && !$email) { - $this->error('Either a --id= or --email= option must be provided.'); - - return 1; - } - - $field = $id ? 'id' : 'email'; - $value = $id ?: $email; - - /** @var User $user */ - $user = User::query() - ->where($field, '=', $value) - ->first(); - - if (!$user) { - $this->error("A user where {$field}={$value} could not be found."); - + try { + $user = $this->fetchProvidedUser(); + } catch (Exception $exception) { + $this->error($exception->getMessage()); return 1; }