Logo du site, favicon et contrôle des inscriptions
SiteSettingsService : persistance JSON dans storage/app/site_settings.json
(pas de migration DB — survit aux mises à jour sans table supplémentaire)
Logo :
- Upload admin (PNG/JPG/SVG/WebP, max 2 Mo) → storage/app/public/site/logo.{ext}
- Favicon <link rel="icon"> injecté dans app.blade.php et guest.blade.php
- Logo affiché dans la barre de navigation (h-8, object-contain)
- Logo affiché sur la page de connexion (guest layout)
- Page d'accueil welcome.blade.php entièrement refaite : logo + bouton connexion
(remplacement du template Laravel par défaut)
- Suppression du logo possible depuis Admin > Paramètres du site
Inscriptions :
- Désactivées par défaut (registration_enabled=false dans site_settings.json)
- RegisteredUserController : redirige vers /login si inscription désactivée
(GET /register → redirect + message ; POST /register → abort 403)
- Page d'accueil : bouton "Créer un compte" masqué si inscriptions désactivées
- Admin > Paramètres du site : toggle checkbox pour activer/désactiver
AppServiceProvider : partage $siteLogoUrl et $registrationEnabled avec toutes les vues
Navigation : lien "Paramètres du site" en bas du menu Administration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\SiteSettingsService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
return view('admin.parametres.index', [
|
||||
'logoUrl' => SiteSettingsService::logoUrl(),
|
||||
'registrationEnabled' => SiteSettingsService::registrationEnabled(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateLogo(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'logo' => ['required', 'file', 'max:2048', 'mimes:png,jpg,jpeg,gif,webp,svg'],
|
||||
]);
|
||||
|
||||
// Supprimer l'ancien logo
|
||||
$old = SiteSettingsService::get('logo_path');
|
||||
if ($old && Storage::disk('public')->exists($old)) {
|
||||
Storage::disk('public')->delete($old);
|
||||
}
|
||||
|
||||
$file = $request->file('logo');
|
||||
$ext = strtolower($file->getClientOriginalExtension());
|
||||
$path = Storage::disk('public')->putFileAs('site', $file, "logo.{$ext}");
|
||||
|
||||
SiteSettingsService::set('logo_path', $path);
|
||||
|
||||
return back()->with('success', 'Logo mis à jour.');
|
||||
}
|
||||
|
||||
public function deleteLogo(): RedirectResponse
|
||||
{
|
||||
$path = SiteSettingsService::get('logo_path');
|
||||
if ($path && Storage::disk('public')->exists($path)) {
|
||||
Storage::disk('public')->delete($path);
|
||||
}
|
||||
|
||||
SiteSettingsService::set('logo_path', null);
|
||||
|
||||
return back()->with('success', 'Logo supprimé.');
|
||||
}
|
||||
|
||||
public function updateSettings(Request $request): RedirectResponse
|
||||
{
|
||||
SiteSettingsService::set('registration_enabled', $request->boolean('registration_enabled'));
|
||||
|
||||
return back()->with('success', 'Paramètres enregistrés.');
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@ namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\SiteSettingsService;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
@@ -18,8 +20,13 @@ class RegisteredUserController extends Controller
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View
|
||||
public function create(): View|RedirectResponse
|
||||
{
|
||||
if (! SiteSettingsService::registrationEnabled()) {
|
||||
return redirect()->route('login')
|
||||
->with('status', 'Les inscriptions sont actuellement désactivées.');
|
||||
}
|
||||
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
@@ -30,6 +37,10 @@ class RegisteredUserController extends Controller
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! SiteSettingsService::registrationEnabled()) {
|
||||
abort(403, 'Les inscriptions sont désactivées.');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
|
||||
@@ -2,23 +2,21 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Services\SiteSettingsService;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
public function register(): void {}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
// Partage le logo et les paramètres globaux avec toutes les vues
|
||||
$logoUrl = SiteSettingsService::logoUrl();
|
||||
$registrationEnabled = SiteSettingsService::registrationEnabled();
|
||||
|
||||
View::share('siteLogoUrl', $logoUrl);
|
||||
View::share('registrationEnabled', $registrationEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class SiteSettingsService
|
||||
{
|
||||
private static function path(): string
|
||||
{
|
||||
return storage_path('app/site_settings.json');
|
||||
}
|
||||
|
||||
private static function load(): array
|
||||
{
|
||||
$path = self::path();
|
||||
if (! file_exists($path)) {
|
||||
return [];
|
||||
}
|
||||
return json_decode(file_get_contents($path), true) ?: [];
|
||||
}
|
||||
|
||||
private static function save(array $settings): void
|
||||
{
|
||||
file_put_contents(self::path(), json_encode($settings, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public static function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return self::load()[$key] ?? $default;
|
||||
}
|
||||
|
||||
public static function set(string $key, mixed $value): void
|
||||
{
|
||||
$settings = self::load();
|
||||
$settings[$key] = $value;
|
||||
self::save($settings);
|
||||
}
|
||||
|
||||
public static function all(): array
|
||||
{
|
||||
return self::load();
|
||||
}
|
||||
|
||||
// ── Logo ─────────────────────────────────────────────────────────────────
|
||||
|
||||
public static function logoUrl(): ?string
|
||||
{
|
||||
$logoPath = self::get('logo_path');
|
||||
if (! $logoPath) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if (! Storage::disk('public')->exists($logoPath)) {
|
||||
return null;
|
||||
}
|
||||
return Storage::disk('public')->url($logoPath);
|
||||
} catch (\Exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Inscriptions ─────────────────────────────────────────────────────────
|
||||
|
||||
public static function registrationEnabled(): bool
|
||||
{
|
||||
// Désactivées par défaut
|
||||
return (bool) self::get('registration_enabled', false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<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>
|
||||
|
||||
{{-- 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>
|
||||
|
||||
<form method="POST" action="{{ route('admin.parametres.update') }}">
|
||||
@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">
|
||||
<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>
|
||||
@@ -5,7 +5,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
|
||||
<title>{{ config('app.name', 'Laravel') }}</title>
|
||||
<title>{{ config('app.name', 'MesRelevés') }}</title>
|
||||
|
||||
@if($siteLogoUrl)
|
||||
<link rel="icon" href="{{ $siteLogoUrl }}">
|
||||
@endif
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
|
||||
<title>{{ config('app.name', 'Laravel') }}</title>
|
||||
<title>{{ config('app.name', 'MesRelevés') }}</title>
|
||||
|
||||
@if($siteLogoUrl)
|
||||
<link rel="icon" href="{{ $siteLogoUrl }}">
|
||||
@endif
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
@@ -16,9 +20,13 @@
|
||||
</head>
|
||||
<body class="font-sans text-gray-900 antialiased">
|
||||
<div class="min-h-screen flex flex-col sm:justify-center items-center pt-6 sm:pt-0 bg-gray-100">
|
||||
<div>
|
||||
<div class="mb-2">
|
||||
<a href="/">
|
||||
<x-application-logo class="w-20 h-20 fill-current text-gray-500" />
|
||||
@if($siteLogoUrl)
|
||||
<img src="{{ $siteLogoUrl }}" alt="{{ config('app.name') }}" class="h-16 w-auto object-contain">
|
||||
@else
|
||||
<x-application-logo class="w-16 h-16 fill-current text-gray-400" />
|
||||
@endif
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -4,8 +4,13 @@
|
||||
<div class="flex">
|
||||
<!-- Logo -->
|
||||
<div class="shrink-0 flex items-center">
|
||||
<a href="{{ route('dashboard') }}" class="font-semibold text-gray-800 text-lg">
|
||||
MesRelevés
|
||||
<a href="{{ route('dashboard') }}" class="flex items-center">
|
||||
@if($siteLogoUrl)
|
||||
<img src="{{ $siteLogoUrl }}" alt="{{ config('app.name') }}"
|
||||
class="h-8 w-auto object-contain max-w-[160px]">
|
||||
@else
|
||||
<span class="font-semibold text-gray-800 text-lg">{{ config('app.name') }}</span>
|
||||
@endif
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -58,6 +63,10 @@
|
||||
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">Types de sources</a>
|
||||
<a href="{{ route('admin.lieu-types.index') }}"
|
||||
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">Types de lieux</a>
|
||||
<div class="border-t border-gray-100 mt-1 pt-1">
|
||||
<a href="{{ route('admin.parametres') }}"
|
||||
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">Paramètres du site</a>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -4,6 +4,7 @@ use App\Http\Controllers\Admin\DashboardController;
|
||||
use App\Http\Controllers\Admin\DepotController;
|
||||
use App\Http\Controllers\Admin\LieuTypeController;
|
||||
use App\Http\Controllers\Admin\SectionController;
|
||||
use App\Http\Controllers\Admin\SettingController;
|
||||
use App\Http\Controllers\Admin\SourceTypeController;
|
||||
use App\Http\Controllers\Admin\UserController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -11,6 +12,12 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::middleware(['auth', 'role:admin'])->prefix('admin')->name('admin.')->group(function () {
|
||||
Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');
|
||||
|
||||
// Paramètres du site (logo, inscriptions)
|
||||
Route::get('parametres', [SettingController::class, 'index'])->name('parametres');
|
||||
Route::post('parametres/logo', [SettingController::class, 'updateLogo'])->name('parametres.logo.update');
|
||||
Route::delete('parametres/logo', [SettingController::class, 'deleteLogo'])->name('parametres.logo.delete');
|
||||
Route::post('parametres/settings', [SettingController::class, 'updateSettings'])->name('parametres.update');
|
||||
|
||||
Route::resource('utilisateurs', UserController::class)->only(['index', 'edit', 'update']);
|
||||
Route::post('utilisateurs/{utilisateur}/toggle-active', [UserController::class, 'toggleActive'])->name('utilisateurs.toggle-active');
|
||||
Route::resource('lieu-types', LieuTypeController::class)
|
||||
|
||||
Reference in New Issue
Block a user