Import/export CSV utilisateurs, filtre statut et titre du site modifiable

Utilisateurs :
- Filtre actif/inactif dans la liste (status=active|inactive)
- Export CSV avec les filtres actifs — séparateur ;, BOM UTF-8 (compatible Excel)
- Import CSV : détection auto du séparateur, validation ligne par ligne,
  mot de passe temporaire généré + affiché une seule fois dans les résultats
- Téléchargement d'un fichier modèle CSV

Paramètres du site :
- Champ "Titre du site" (site_name dans site_settings.json)
- Titre partagé via SiteSettingsService::siteName() et injecté dans config('app.name')
  au boot — s'applique partout sans modifier .env

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 18:48:36 +02:00
parent f341f822ab
commit b608501f39
8 changed files with 434 additions and 39 deletions
@@ -95,24 +95,51 @@
</div>
</div>
{{-- Inscriptions --}}
<div class="bg-white shadow rounded-lg p-6 space-y-4">
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Inscriptions</h3>
<p class="text-sm text-gray-500">
Autorise ou non les visiteurs à créer un compte via la page d'inscription publique.
Quand désactivées, seul un administrateur peut créer des comptes (via la gestion des utilisateurs).
</p>
{{-- 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') }}">
<form method="POST" action="{{ route('admin.parametres.update') }}" class="space-y-5">
@csrf
<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 class="mt-4">
{{-- 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
@@ -0,0 +1,132 @@
<x-app-layout>
<x-slot name="header">
<div class="flex items-center justify-between">
<h2 class="text-xl font-semibold text-gray-800">Importer des utilisateurs</h2>
<a href="{{ route('admin.utilisateurs.index') }}"
class="text-sm text-indigo-600 hover:underline"> Retour à la liste</a>
</div>
</x-slot>
<div class="py-8 max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6">
{{-- Résultats d'import --}}
@if(isset($results))
<div class="bg-white shadow rounded-lg p-6 space-y-4">
<div class="flex items-center gap-4">
@if($created > 0)
<span class="text-green-700 font-semibold text-sm">
{{ $created }} compte{{ $created > 1 ? 's' : '' }} créé{{ $created > 1 ? 's' : '' }}
</span>
@endif
@if($errors > 0)
<span class="text-red-600 font-semibold text-sm">
{{ $errors }} ligne{{ $errors > 1 ? 's' : '' }} en erreur
</span>
@endif
</div>
@if($created > 0)
<div class="p-3 bg-amber-50 border border-amber-200 rounded-lg text-xs text-amber-800">
Les mots de passe temporaires ci-dessous sont affichés <strong>une seule fois</strong>.
Notez-les et communiquez-les aux utilisateurs concernés. Ils pourront les changer via leur profil.
</div>
@endif
<div class="overflow-x-auto">
<table class="min-w-full text-sm divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Ligne</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Nom</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">E-mail</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Rôle</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Mot de passe temporaire</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Statut</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
@foreach($results as $r)
<tr class="{{ $r['ok'] ? '' : 'bg-red-50' }}">
<td class="px-4 py-2 text-gray-400">{{ $r['line'] }}</td>
<td class="px-4 py-2 font-medium text-gray-900">{{ $r['name'] }}</td>
<td class="px-4 py-2 text-gray-600">{{ $r['email'] }}</td>
<td class="px-4 py-2 text-gray-500">{{ $r['role'] ?? '' }}</td>
<td class="px-4 py-2 font-mono text-indigo-700">
{{ $r['ok'] ? $r['password'] : '' }}
</td>
<td class="px-4 py-2">
@if($r['ok'])
<span class="text-green-700 font-medium"> Créé</span>
@else
<span class="text-red-600 text-xs">{{ $r['error'] }}</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="pt-2">
<a href="{{ route('admin.utilisateurs.index') }}"
class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700 inline-block">
Voir la liste des utilisateurs
</a>
</div>
</div>
@endif
{{-- Formulaire d'import --}}
<div class="bg-white shadow rounded-lg p-6 space-y-5">
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Importer un fichier CSV</h3>
@if($errors->any())
<div class="p-4 bg-red-50 border border-red-200 text-red-700 text-sm rounded-md space-y-1">
@foreach($errors->all() as $e)<p>{{ $e }}</p>@endforeach
</div>
@endif
<div class="p-4 bg-blue-50 border border-blue-200 rounded-lg text-sm text-blue-800 space-y-1">
<p class="font-semibold">Format attendu du fichier CSV :</p>
<ul class="list-disc list-inside text-xs space-y-0.5">
<li>Séparateur : <code class="bg-blue-100 px-1 rounded">;</code> ou <code class="bg-blue-100 px-1 rounded">,</code></li>
<li>Encodage : UTF-8 (avec ou sans BOM)</li>
<li>Colonnes obligatoires : <code class="bg-blue-100 px-1 rounded">name</code>, <code class="bg-blue-100 px-1 rounded">email</code>, <code class="bg-blue-100 px-1 rounded">role</code></li>
<li>Colonne optionnelle : <code class="bg-blue-100 px-1 rounded">is_active</code> (1 ou 0, défaut : 1)</li>
<li>Valeurs acceptées pour <code class="bg-blue-100 px-1 rounded">role</code> :
<code class="bg-blue-100 px-1 rounded">member</code>,
<code class="bg-blue-100 px-1 rounded">section_manager</code>,
<code class="bg-blue-100 px-1 rounded">admin</code>
</li>
<li>Un mot de passe temporaire aléatoire sera généré pour chaque compte importé.</li>
</ul>
<a href="{{ route('admin.utilisateurs.import.modele') }}"
class="inline-block mt-2 text-xs text-indigo-700 font-medium hover:underline">
Télécharger le fichier modèle (CSV)
</a>
</div>
<form method="POST" action="{{ route('admin.utilisateurs.import.store') }}"
enctype="multipart/form-data" class="space-y-4">
@csrf
<div>
<label for="file" class="block text-sm font-medium text-gray-700 mb-1">
Fichier CSV <span class="text-red-500">*</span>
</label>
<input type="file" id="file" name="file" accept=".csv,.txt" required
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">Taille maximale : 2 Mo.</p>
@error('file') <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">
Importer
</button>
</form>
</div>
</div>
</x-app-layout>
@@ -1,24 +1,59 @@
<x-app-layout>
<x-slot name="header">
<h2 class="text-xl font-semibold text-gray-800">Gestion des utilisateurs</h2>
<div class="flex items-center justify-between">
<h2 class="text-xl font-semibold text-gray-800">Gestion des utilisateurs</h2>
<div class="flex items-center gap-3">
<a href="{{ route('admin.utilisateurs.import') }}"
class="flex items-center gap-1.5 px-4 py-2 border border-gray-300 text-sm text-gray-700 rounded-md hover:bg-gray-50 transition-colors">
<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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
</svg>
Importer CSV
</a>
<a href="{{ route('admin.utilisateurs.export', request()->only(['role', 'status', 'q'])) }}"
class="flex items-center gap-1.5 px-4 py-2 border border-gray-300 text-sm text-gray-700 rounded-md hover:bg-gray-50 transition-colors">
<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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4 4m0 0l4 4m-4-4h12"/>
</svg>
Exporter CSV
</a>
</div>
</div>
</x-slot>
<div class="py-8 max-w-7xl 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 text-sm rounded-md">
{{ session('success') }}
</div>
@endif
@if(session('error'))
<div class="p-4 bg-red-50 border border-red-200 text-red-800 text-sm rounded-md">
{{ session('error') }}
</div>
@endif
{{-- Filtres --}}
@php $hasFilters = request()->anyFilled(['role', 'q']); @endphp
@php $hasFilters = request()->anyFilled(['role', 'q', 'status']); @endphp
<div class="bg-white shadow rounded-lg p-5">
<form method="GET" action="{{ route('admin.utilisateurs.index') }}" class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[200px]">
<form method="GET" action="{{ route('admin.utilisateurs.index') }}"
class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[180px]">
<label class="block text-xs font-medium text-gray-600 mb-1">Recherche</label>
<input type="text" name="q" value="{{ request('q') }}"
placeholder="Nom ou e-mail…"
class="block w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
class="block w-full rounded-md border-gray-300 shadow-sm text-sm
focus:border-indigo-500 focus:ring-indigo-500">
</div>
<div class="w-52">
<div class="w-44">
<label class="block text-xs font-medium text-gray-600 mb-1">Rôle</label>
<select name="role"
class="block w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
class="block w-full rounded-md border-gray-300 shadow-sm text-sm
focus:border-indigo-500 focus:ring-indigo-500">
<option value=""> Tous </option>
@foreach(\App\Enums\UserRole::cases() as $r)
<option value="{{ $r->value }}" {{ request('role') === $r->value ? 'selected' : '' }}>
@@ -27,6 +62,18 @@
@endforeach
</select>
</div>
<div class="w-40">
<label class="block text-xs font-medium text-gray-600 mb-1">Statut</label>
<select name="status"
class="block w-full rounded-md border-gray-300 shadow-sm text-sm
focus:border-indigo-500 focus:ring-indigo-500">
<option value=""> Tous </option>
<option value="active" {{ request('status') === 'active' ? 'selected' : '' }}>Actifs</option>
<option value="inactive" {{ request('status') === 'inactive' ? 'selected' : '' }}>Inactifs</option>
</select>
</div>
<div class="flex items-center gap-3">
<button type="submit"
class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">
@@ -51,7 +98,7 @@
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">E-mail</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Rôle</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Sections</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Sources assignées</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Sources</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Inscrit le</th>
<th class="px-6 py-3"></th>
</tr>
@@ -85,11 +132,7 @@
</span>
</td>
<td class="px-6 py-4 text-gray-500">
@if($user->sections->isNotEmpty())
{{ $user->sections->pluck('nom')->join(', ') }}
@else
@endif
{{ $user->sections->isNotEmpty() ? $user->sections->pluck('nom')->join(', ') : '—' }}
</td>
<td class="px-6 py-4 text-gray-500">{{ $user->sources_assignees_count ?: '—' }}</td>
<td class="px-6 py-4 text-gray-500 whitespace-nowrap">
@@ -98,10 +141,9 @@
<td class="px-6 py-4 text-right space-x-3">
@if($user->id !== auth()->id())
<a href="{{ route('admin.utilisateurs.edit', $user) }}"
class="text-indigo-600 hover:underline text-sm">
Modifier
</a>
<form method="POST" action="{{ route('admin.utilisateurs.toggle-active', $user) }}"
class="text-indigo-600 hover:underline text-sm">Modifier</a>
<form method="POST"
action="{{ route('admin.utilisateurs.toggle-active', $user) }}"
class="inline" x-data
@submit.prevent="if(confirm('{{ $user->is_active ? 'Désactiver' : 'Activer' }} ce compte ?')) $el.submit()">
@csrf
@@ -126,5 +168,6 @@
<div class="px-6 py-4 border-t">{{ $users->links() }}</div>
@endif
</div>
</div>
</x-app-layout>