Configuration SMTP et 2FA par code PIN e-mail

Paramètres du site :
- Nouvelle section "Serveur SMTP" avec host, port, chiffrement,
  identifiant, mot de passe, adresse/nom d'expéditeur
- Bouton "Envoyer un e-mail de test" (AJAX via Symfony EsmtpTransport) :
  tente la connexion + envoie un message réel à l'admin
- Badge "Configuré — 2FA actif" quand SMTP est en place
- Suppression de la configuration possible

Authentification 2FA :
- Si SMTP configuré : après validation identifiant/mot de passe,
  l'utilisateur est déconnecté, un PIN à 6 chiffres est généré,
  haché (bcrypt) et stocké en session, envoyé par e-mail (10 min)
- Page /2fa : saisie du PIN, bouton "Renvoyer le code", retour login
- Si l'envoi e-mail échoue : fallback sans 2FA (logue l'erreur)
- Si SMTP non configuré : login standard inchangé

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 18:59:18 +02:00
parent e6f4d0c565
commit 07ab2a7063
11 changed files with 564 additions and 19 deletions
+52
View File
@@ -0,0 +1,52 @@
<x-guest-layout>
<div class="mb-6 text-center">
<div class="inline-flex items-center justify-center w-14 h-14 rounded-full bg-indigo-100 mb-3">
<svg class="w-7 h-7 text-indigo-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
</svg>
</div>
<h2 class="text-lg font-semibold text-gray-900">Vérification en deux étapes</h2>
<p class="text-sm text-gray-500 mt-1">
Un code à 6 chiffres a été envoyé à<br>
<span class="font-medium text-gray-700">{{ $maskedEmail }}</span>
</p>
</div>
@if(session('resent'))
<div class="mb-4 p-3 bg-green-50 border border-green-200 text-green-800 text-sm rounded-md text-center">
Un nouveau code a été envoyé.
</div>
@endif
<form method="POST" action="{{ route('2fa.verify') }}">
@csrf
<div class="mb-5">
<x-input-label for="pin" value="Code PIN"/>
<input type="text" id="pin" name="pin"
inputmode="numeric" pattern="[0-9]{6}" maxlength="6" autocomplete="one-time-code"
autofocus required
class="mt-1 block w-full text-center text-3xl tracking-[.5em] font-mono
border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
placeholder="——————">
<x-input-error :messages="$errors->get('pin')" class="mt-2"/>
</div>
<x-primary-button class="w-full justify-center py-3">
Valider le code
</x-primary-button>
</form>
<div class="mt-5 flex flex-col items-center gap-2">
<form method="POST" action="{{ route('2fa.resend') }}">
@csrf
<button type="submit" class="text-sm text-indigo-600 hover:underline">
Renvoyer le code
</button>
</form>
<a href="{{ route('login') }}" class="text-sm text-gray-400 hover:text-gray-600">
Retour à la connexion
</a>
</div>
</x-guest-layout>