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>
91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?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;
|
|
}
|
|
}
|
|
|
|
// ── SMTP ─────────────────────────────────────────────────────────────────
|
|
|
|
public static function smtpConfig(): array
|
|
{
|
|
return self::get('smtp', []);
|
|
}
|
|
|
|
public static function smtpConfigured(): bool
|
|
{
|
|
$smtp = self::smtpConfig();
|
|
return ! empty($smtp['host']) && ! empty($smtp['port']);
|
|
}
|
|
|
|
// ── Titre du site ─────────────────────────────────────────────────────────
|
|
|
|
public static function siteName(): string
|
|
{
|
|
return self::get('site_name') ?: config('app.name', 'MesRelevés');
|
|
}
|
|
|
|
// ── Inscriptions ─────────────────────────────────────────────────────────
|
|
|
|
public static function registrationEnabled(): bool
|
|
{
|
|
// Désactivées par défaut
|
|
return (bool) self::get('registration_enabled', false);
|
|
}
|
|
}
|