user()->two_factor_confirmed_at)) { $disableTwoFactorAuthentication(auth()->user()); } $this->twoFactorEnabled = auth()->user()->hasEnabledTwoFactorAuthentication(); $this->requiresConfirmation = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm'); } /** * Enable two-factor authentication for the user. */ public function enable(EnableTwoFactorAuthentication $enableTwoFactorAuthentication): void { $enableTwoFactorAuthentication(auth()->user()); if (! $this->requiresConfirmation) { $this->twoFactorEnabled = auth()->user()->hasEnabledTwoFactorAuthentication(); } $this->loadSetupData(); $this->showModal = true; } /** * Load the two-factor authentication setup data for the user. */ private function loadSetupData(): void { $user = auth()->user(); try { $this->qrCodeSvg = $user?->twoFactorQrCodeSvg(); $this->manualSetupKey = decrypt($user->two_factor_secret); } catch (Exception) { $this->addError('setupData', 'Failed to fetch setup data.'); $this->reset('qrCodeSvg', 'manualSetupKey'); } } /** * Show the two-factor verification step if necessary. */ public function showVerificationIfNecessary(): void { if ($this->requiresConfirmation) { $this->showVerificationStep = true; $this->resetErrorBag(); return; } $this->closeModal(); } /** * Confirm two-factor authentication for the user. */ public function confirmTwoFactor(ConfirmTwoFactorAuthentication $confirmTwoFactorAuthentication): void { $this->validate(); $confirmTwoFactorAuthentication(auth()->user(), $this->code); $this->closeModal(); $this->twoFactorEnabled = true; } /** * Reset two-factor verification state. */ public function resetVerification(): void { $this->reset('code', 'showVerificationStep'); $this->resetErrorBag(); } /** * Disable two-factor authentication for the user. */ public function disable(DisableTwoFactorAuthentication $disableTwoFactorAuthentication): void { $disableTwoFactorAuthentication(auth()->user()); $this->twoFactorEnabled = false; } /** * Close the two-factor authentication modal. */ public function closeModal(): void { $this->reset( 'code', 'manualSetupKey', 'qrCodeSvg', 'showModal', 'showVerificationStep', ); $this->resetErrorBag(); if (! $this->requiresConfirmation) { $this->twoFactorEnabled = auth()->user()->hasEnabledTwoFactorAuthentication(); } } /** * Get the current modal configuration state. */ public function getModalConfigProperty(): array { if ($this->twoFactorEnabled) { return [ 'title' => __('Two-Factor Authentication Enabled'), 'description' => __('Two-factor authentication is now enabled. Scan the QR code or enter the setup key in your authenticator app.'), 'buttonText' => __('Close'), ]; } if ($this->showVerificationStep) { return [ 'title' => __('Verify Authentication Code'), 'description' => __('Enter the 6-digit code from your authenticator app.'), 'buttonText' => __('Continue'), ]; } return [ 'title' => __('Enable Two-Factor Authentication'), 'description' => __('To finish enabling two-factor authentication, scan the QR code or enter the setup key in your authenticator app.'), 'buttonText' => __('Continue'), ]; } } ?>
@include('partials.settings-heading')
@if ($twoFactorEnabled)
{{ __('Enabled') }}
{{ __('With two-factor authentication enabled, you will be prompted for a secure, random pin during login, which you can retrieve from the TOTP-supported application on your phone.') }}
{{ __('Disable 2FA') }}
@else
{{ __('Disabled') }}
{{ __('When you enable two-factor authentication, you will be prompted for a secure pin during login. This pin can be retrieved from a TOTP-supported application on your phone.') }} {{ __('Enable 2FA') }}
@endif
@for ($i = 1; $i <= 5; $i++)
@endfor
@for ($i = 1; $i <= 5; $i++)
@endfor
{{ $this->modalConfig['title'] }} {{ $this->modalConfig['description'] }}
@if ($showVerificationStep)
{{ __('Back') }} {{ __('Confirm') }}
@else @error('setupData') @enderror
@empty($qrCodeSvg)
@else
{!! $qrCodeSvg !!}
@endempty
{{ $this->modalConfig['buttonText'] }}
{{ __('or, enter the code manually') }}
@empty($manualSetupKey)
@else @endempty
@endif