|
| 1 | +<x-layouts.app title="Two-factor authentication"> |
| 2 | + @php |
| 3 | + $user = auth()->user(); |
| 4 | +
|
| 5 | + /* |
| 6 | + * Not hasEnabledTwoFactorAuthentication(): with the confirm option on, that |
| 7 | + * method stays false until the user has entered a code, so a page keyed on |
| 8 | + * it would offer "turn on" forever and never let anyone finish. What matters |
| 9 | + * here is whether a secret exists yet, and whether it has been confirmed. |
| 10 | + */ |
| 11 | + $started = ! is_null($user->two_factor_secret); |
| 12 | + $confirmed = ! is_null($user->two_factor_confirmed_at); |
| 13 | + @endphp |
| 14 | + |
| 15 | + <x-aura::heading level="1">Settings</x-aura::heading> |
| 16 | + <x-settings-nav current="settings.two-factor" /> |
| 17 | + |
| 18 | + @if (session('status') === 'two-factor-authentication-enabled') |
| 19 | + <x-aura::alert variant="info" class="mb-6"> |
| 20 | + Scan the code below with your authenticator app, then enter the six digits it shows to finish. |
| 21 | + </x-aura::alert> |
| 22 | + @endif |
| 23 | + |
| 24 | + @if (session('status') === 'two-factor-authentication-confirmed') |
| 25 | + <x-aura::alert variant="success" class="mb-6">Two-factor authentication is on.</x-aura::alert> |
| 26 | + @endif |
| 27 | + |
| 28 | + @if (session('status') === 'two-factor-authentication-disabled') |
| 29 | + <x-aura::alert variant="success" class="mb-6">Two-factor authentication is off.</x-aura::alert> |
| 30 | + @endif |
| 31 | + |
| 32 | + <x-aura::card class="max-w-2xl"> |
| 33 | + <div class="mb-1 flex items-center gap-3"> |
| 34 | + <x-aura::heading level="2">Two-factor authentication</x-aura::heading> |
| 35 | + @if ($confirmed) |
| 36 | + <x-aura::badge variant="success">On</x-aura::badge> |
| 37 | + @elseif ($started) |
| 38 | + <x-aura::badge variant="warning">Waiting for confirmation</x-aura::badge> |
| 39 | + @else |
| 40 | + <x-aura::badge variant="secondary">Off</x-aura::badge> |
| 41 | + @endif |
| 42 | + </div> |
| 43 | + |
| 44 | + <x-aura::text class="mb-6 text-sm"> |
| 45 | + A second step at sign-in: a six-digit code from an app on your phone, so a stolen |
| 46 | + password is not enough on its own. |
| 47 | + </x-aura::text> |
| 48 | + |
| 49 | + @if (! $started) |
| 50 | + <form method="POST" action="{{ route('two-factor.enable') }}"> |
| 51 | + @csrf |
| 52 | + <x-aura::button type="submit" variant="primary">Turn on</x-aura::button> |
| 53 | + </form> |
| 54 | + @else |
| 55 | + @unless ($confirmed) |
| 56 | + {{-- The secret is shown once, while it is being set up, and never again. |
| 57 | + The QR is rendered by Fortify from the user's own secret. --}} |
| 58 | + <div class="mb-6 flex flex-wrap items-start gap-6"> |
| 59 | + <div class="rounded-lg bg-white p-3">{!! $user->twoFactorQrCodeSvg() !!}</div> |
| 60 | + |
| 61 | + <div class="text-sm"> |
| 62 | + <p class="mb-2 text-gray-600 dark:text-gray-400">Cannot scan it? Enter this key by hand:</p> |
| 63 | + <code class="break-all">{{ decrypt($user->two_factor_secret) }}</code> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + |
| 67 | + <form method="POST" action="{{ route('two-factor.confirm') }}" class="aura-form-fluid mb-8 space-y-4"> |
| 68 | + @csrf |
| 69 | + |
| 70 | + <x-aura::input |
| 71 | + label="Code from your app" |
| 72 | + name="code" |
| 73 | + inputmode="numeric" |
| 74 | + autocomplete="one-time-code" |
| 75 | + required |
| 76 | + :error="$errors->confirmTwoFactorAuthentication->first('code')" |
| 77 | + /> |
| 78 | + |
| 79 | + <x-aura::button type="submit" variant="primary">Finish turning it on</x-aura::button> |
| 80 | + </form> |
| 81 | + @endunless |
| 82 | + |
| 83 | + <div class="mb-8"> |
| 84 | + <x-aura::heading level="3" class="mb-1">Recovery codes</x-aura::heading> |
| 85 | + <x-aura::text class="mb-4 text-sm"> |
| 86 | + Each one signs you in once, for when the phone is not to hand. Keep them |
| 87 | + somewhere other than the phone. |
| 88 | + </x-aura::text> |
| 89 | + |
| 90 | + <ul class="mb-4 grid gap-1 font-mono text-sm sm:grid-cols-2"> |
| 91 | + @foreach ($user->recoveryCodes() as $code) |
| 92 | + <li>{{ $code }}</li> |
| 93 | + @endforeach |
| 94 | + </ul> |
| 95 | + |
| 96 | + <form method="POST" action="{{ route('two-factor.regenerate-recovery-codes') }}"> |
| 97 | + @csrf |
| 98 | + <x-aura::button type="submit" variant="secondary" size="sm">Generate new codes</x-aura::button> |
| 99 | + </form> |
| 100 | + </div> |
| 101 | + |
| 102 | + <form method="POST" action="{{ route('two-factor.disable') }}"> |
| 103 | + @csrf |
| 104 | + @method('DELETE') |
| 105 | + <x-aura::button type="submit" variant="danger">Turn off</x-aura::button> |
| 106 | + </form> |
| 107 | + @endif |
| 108 | + </x-aura::card> |
| 109 | +</x-layouts.app> |
0 commit comments