07ab2a7063
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>
314 lines
18 KiB
PHP
314 lines
18 KiB
PHP
<x-app-layout>
|
|
<x-slot name="header">
|
|
<h2 class="text-xl font-semibold text-gray-800">Paramètres du site</h2>
|
|
</x-slot>
|
|
|
|
<div class="py-8 max-w-2xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6">
|
|
|
|
@if(session('success'))
|
|
<div class="p-4 bg-green-50 border border-green-200 text-green-800 rounded-md">{{ session('success') }}</div>
|
|
@endif
|
|
|
|
{{-- Logo --}}
|
|
<div class="bg-white shadow rounded-lg p-6 space-y-5">
|
|
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Logo du site</h3>
|
|
|
|
@if($logoUrl)
|
|
<div class="flex items-center gap-6">
|
|
<img src="{{ $logoUrl }}" alt="Logo actuel" class="h-20 w-auto object-contain rounded border border-gray-200 p-2">
|
|
<div>
|
|
<p class="text-sm text-gray-600 mb-2">Logo actuel</p>
|
|
<form method="POST" action="{{ route('admin.parametres.logo.delete') }}"
|
|
x-data @submit.prevent="if(confirm('Supprimer le logo ?')) $el.submit()">
|
|
@csrf @method('DELETE')
|
|
<button type="submit" class="text-sm text-red-500 hover:text-red-700">Supprimer</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
@else
|
|
<p class="text-sm text-gray-400">Aucun logo configuré — le nom de l'application est affiché.</p>
|
|
@endif
|
|
|
|
<form method="POST" action="{{ route('admin.parametres.logo.update') }}"
|
|
enctype="multipart/form-data" class="space-y-4">
|
|
@csrf
|
|
<div>
|
|
<label for="logo" class="block text-sm font-medium text-gray-700 mb-1">
|
|
{{ $logoUrl ? 'Remplacer le logo' : 'Téléverser un logo' }}
|
|
</label>
|
|
<input type="file" id="logo" name="logo" accept="image/*"
|
|
class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-medium file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100">
|
|
<p class="mt-1 text-xs text-gray-400">PNG, JPG, SVG ou WebP · max 2 Mo · format recommandé : carré ou paysage, fond transparent</p>
|
|
@error('logo') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
<button type="submit"
|
|
class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">
|
|
Enregistrer le logo
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
{{-- SMTP --}}
|
|
@php $smtp = \App\Services\SiteSettingsService::smtpConfig(); @endphp
|
|
<div class="bg-white shadow rounded-lg p-6 space-y-5"
|
|
x-data="{
|
|
host: '{{ $smtp['host'] ?? '' }}',
|
|
port: '{{ $smtp['port'] ?? 587 }}',
|
|
encryption: '{{ $smtp['encryption'] ?? 'tls' }}',
|
|
username: '{{ $smtp['username'] ?? '' }}',
|
|
password: '{{ $smtp['password'] ?? '' }}',
|
|
fromAddress: '{{ $smtp['from_address'] ?? '' }}',
|
|
fromName: '{{ $smtp['from_name'] ?? $siteName }}',
|
|
testing: false,
|
|
tested: false,
|
|
testOk: false,
|
|
testMsg: '',
|
|
|
|
async testSmtp() {
|
|
this.testing = true;
|
|
this.tested = false;
|
|
try {
|
|
const resp = await fetch('{{ route('admin.parametres.smtp.test') }}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content,
|
|
},
|
|
body: JSON.stringify({
|
|
smtp_host: this.host,
|
|
smtp_port: parseInt(this.port),
|
|
smtp_encryption: this.encryption,
|
|
smtp_username: this.username,
|
|
smtp_password: this.password,
|
|
smtp_from_address: this.fromAddress,
|
|
smtp_from_name: this.fromName,
|
|
}),
|
|
});
|
|
const data = await resp.json();
|
|
this.testOk = data.ok;
|
|
this.testMsg = data.message;
|
|
} catch (e) {
|
|
this.testOk = false;
|
|
this.testMsg = 'Erreur réseau : ' + e.message;
|
|
}
|
|
this.testing = false;
|
|
this.tested = true;
|
|
}
|
|
}">
|
|
|
|
<div class="flex items-start justify-between">
|
|
<div>
|
|
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Serveur SMTP</h3>
|
|
<p class="text-xs text-gray-400 mt-0.5">
|
|
Quand configuré, la connexion nécessitera un code PIN envoyé par e-mail (2FA).
|
|
</p>
|
|
</div>
|
|
@if(\App\Services\SiteSettingsService::smtpConfigured())
|
|
<span class="inline-flex items-center gap-1.5 text-xs text-green-700 bg-green-50 border border-green-200 px-2.5 py-1 rounded-full">
|
|
<svg class="w-3 h-3 fill-current" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
|
|
</svg>
|
|
Configuré — 2FA actif
|
|
</span>
|
|
@endif
|
|
</div>
|
|
|
|
<form method="POST" action="{{ route('admin.parametres.smtp.update') }}" class="space-y-4">
|
|
@csrf
|
|
|
|
<div class="grid grid-cols-3 gap-4">
|
|
<div class="col-span-2">
|
|
<label class="block text-sm font-medium text-gray-700 mb-1">Hôte SMTP</label>
|
|
<input type="text" name="smtp_host" x-model="host"
|
|
placeholder="smtp.exemple.fr"
|
|
class="w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
|
|
@error('smtp_host') <p class="mt-1 text-xs text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-1">Port</label>
|
|
<input type="number" name="smtp_port" x-model="port"
|
|
class="w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
|
|
@error('smtp_port') <p class="mt-1 text-xs text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-1">Chiffrement</label>
|
|
<select name="smtp_encryption" x-model="encryption"
|
|
class="w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
|
|
<option value="tls">TLS / STARTTLS (port 587 recommandé)</option>
|
|
<option value="ssl">SSL (port 465)</option>
|
|
<option value="">Aucun (déconseillé)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-1">Identifiant</label>
|
|
<input type="text" name="smtp_username" x-model="username"
|
|
autocomplete="off"
|
|
class="w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-1">Mot de passe</label>
|
|
<input type="password" name="smtp_password" x-model="password"
|
|
autocomplete="new-password"
|
|
class="w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500"
|
|
placeholder="{{ \App\Services\SiteSettingsService::smtpConfigured() ? '(inchangé si vide)' : '' }}">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-2 gap-4 pt-2 border-t border-gray-100">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-1">Adresse d'expéditeur</label>
|
|
<input type="email" name="smtp_from_address" x-model="fromAddress"
|
|
placeholder="noreply@exemple.fr"
|
|
class="w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
|
|
@error('smtp_from_address') <p class="mt-1 text-xs text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-1">Nom d'expéditeur</label>
|
|
<input type="text" name="smtp_from_name" x-model="fromName"
|
|
class="w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
|
|
@error('smtp_from_name') <p class="mt-1 text-xs text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Résultat test --}}
|
|
<div x-show="tested" x-cloak class="p-3 rounded-lg text-sm flex items-start gap-2"
|
|
:class="testOk ? 'bg-green-50 border border-green-200 text-green-800' : 'bg-red-50 border border-red-200 text-red-800'">
|
|
<span x-text="testOk ? '✓' : '✗'" class="font-bold shrink-0"></span>
|
|
<span x-text="testMsg" class="break-all"></span>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-3 flex-wrap">
|
|
<button type="button" @click="testSmtp()" :disabled="testing"
|
|
class="flex items-center gap-1.5 px-4 py-2 border border-slate-300 bg-slate-50 text-slate-700
|
|
text-sm font-medium rounded-md hover:bg-slate-100 transition disabled:opacity-50">
|
|
<svg class="w-4 h-4" 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>
|
|
<span x-text="testing ? 'Envoi en cours…' : 'Envoyer un e-mail de test'"></span>
|
|
</button>
|
|
|
|
<button type="submit"
|
|
class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">
|
|
Enregistrer
|
|
</button>
|
|
|
|
@if(\App\Services\SiteSettingsService::smtpConfigured())
|
|
<form method="POST" action="{{ route('admin.parametres.smtp.delete') }}" class="ml-auto"
|
|
x-data @submit.prevent="if(confirm('Supprimer la configuration SMTP et désactiver le 2FA ?')) $el.submit()">
|
|
@csrf @method('DELETE')
|
|
<button type="submit" class="text-sm text-red-500 hover:text-red-700">
|
|
Supprimer la configuration
|
|
</button>
|
|
</form>
|
|
@endif
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
{{-- Version --}}
|
|
<div class="bg-white shadow rounded-lg p-6 space-y-4">
|
|
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Version du logiciel</h3>
|
|
|
|
@if($updateAvailable)
|
|
<div class="flex items-start gap-3 p-4 bg-indigo-50 border border-indigo-200 rounded-lg">
|
|
<svg class="w-5 h-5 text-indigo-500 shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/>
|
|
</svg>
|
|
<div>
|
|
<p class="text-sm font-semibold text-indigo-800">
|
|
Mise à jour disponible : v{{ $latestRelease['version'] }}
|
|
</p>
|
|
@if($latestRelease['published_at'])
|
|
<p class="text-xs text-indigo-500 mt-0.5">
|
|
Publié {{ \Carbon\Carbon::parse($latestRelease['published_at'])->diffForHumans() }}
|
|
</p>
|
|
@endif
|
|
<p class="text-xs text-indigo-600 mt-2 font-mono bg-indigo-100 inline-block px-2 py-1 rounded">
|
|
php artisan app:update
|
|
</p>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<p class="text-sm text-gray-700 font-medium">MesRelevés v{{ $installedVersion }}</p>
|
|
@php $installedAt = storage_path('installed'); @endphp
|
|
@if(file_exists($installedAt))
|
|
<p class="text-xs text-gray-400 mt-0.5">
|
|
Installé le {{ \Carbon\Carbon::createFromTimestamp(filemtime($installedAt))->isoFormat('LL') }}
|
|
</p>
|
|
@endif
|
|
</div>
|
|
@if(! $updateAvailable)
|
|
<span class="inline-flex items-center gap-1.5 text-xs text-green-700 bg-green-50 border border-green-200 px-3 py-1.5 rounded-full">
|
|
<svg class="w-3.5 h-3.5" fill="currentColor" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
|
|
</svg>
|
|
À jour
|
|
</span>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Titre du site + Inscriptions (formulaire commun) --}}
|
|
<div class="bg-white shadow rounded-lg p-6 space-y-6">
|
|
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Paramètres généraux</h3>
|
|
|
|
<form method="POST" action="{{ route('admin.parametres.update') }}" class="space-y-5">
|
|
@csrf
|
|
|
|
{{-- Titre du site --}}
|
|
<div>
|
|
<label for="site_name" class="block text-sm font-medium text-gray-700 mb-1">
|
|
Titre du site
|
|
</label>
|
|
<input type="text" id="site_name" name="site_name"
|
|
value="{{ old('site_name', \App\Services\SiteSettingsService::get('site_name')) }}"
|
|
placeholder="{{ config('app.name', 'MesRelevés') }}"
|
|
maxlength="100"
|
|
class="block w-full rounded-md border-gray-300 shadow-sm text-sm
|
|
focus:border-indigo-500 focus:ring-indigo-500">
|
|
<p class="mt-1 text-xs text-gray-400">
|
|
Affiché dans la navigation, les e-mails et les exports.
|
|
Laisser vide pour utiliser la valeur par défaut
|
|
(« {{ config('app.name', 'MesRelevés') }} »).
|
|
</p>
|
|
@error('site_name')
|
|
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
{{-- Inscriptions --}}
|
|
<div class="pt-4 border-t border-gray-100">
|
|
<p class="text-sm font-medium text-gray-700 mb-2">Inscription publique des comptes</p>
|
|
<p class="text-xs text-gray-500 mb-3">
|
|
Autorise ou non les visiteurs à créer un compte via la page d'inscription.
|
|
Quand désactivée, seul un administrateur peut créer des comptes.
|
|
</p>
|
|
<label class="flex items-center gap-3 cursor-pointer">
|
|
<input type="hidden" name="registration_enabled" value="0">
|
|
<input type="checkbox" name="registration_enabled" value="1"
|
|
{{ $registrationEnabled ? 'checked' : '' }}
|
|
class="w-4 h-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500">
|
|
<span class="text-sm text-gray-700">Autoriser l'inscription de nouveaux comptes</span>
|
|
</label>
|
|
</div>
|
|
|
|
<div>
|
|
<button type="submit"
|
|
class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">
|
|
Enregistrer
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</x-app-layout>
|