feat: enforce SMTP configuration validation and show warning notices before enabling Email 2FA

This commit is contained in:
2026-05-21 21:55:00 +07:00
parent 4741a2dff2
commit 41bef637c9
38 changed files with 168 additions and 136 deletions
+20 -5
View File
@@ -34,15 +34,30 @@ class SettingsController extends Controller
$qrCode = 'data:image/svg+xml;base64,' . base64_encode((new \BaconQrCode\Writer($renderer))->writeString($otpUrl));
}
$mailDriver = config('mail.default');
$mailHost = \App\Models\Setting::where('key', 'mail_host')->first()?->value ?: config('mail.mailers.smtp.host');
$smtpConfigured = false;
if ($mailDriver === 'log') {
$smtpConfigured = true;
} elseif ($mailHost === 'mailpit') {
$smtpConfigured = true;
} else {
$mailUsername = \App\Models\Setting::where('key', 'mail_username')->first()?->value ?: config('mail.mailers.smtp.username');
$mailPassword = \App\Models\Setting::where('key', 'mail_password')->first()?->value ?: config('mail.mailers.smtp.password');
$smtpConfigured = !empty($mailHost) && !empty($mailUsername) && !empty($mailPassword);
}
return Inertia::render('Settings/Index', [
'mustVerifyEmail' => $user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail,
'status' => session('status'),
'twoFactor' => [
'enabled' => $twoFactorEnabled,
'qr_code' => $qrCode,
'secret' => $secret,
'email_enabled' => (bool)$user->email_2fa_enabled,
'recovery_codes' => $user->two_factor_recovery_codes
'enabled' => $twoFactorEnabled,
'qr_code' => $qrCode,
'secret' => $secret,
'email_enabled' => (bool)$user->email_2fa_enabled,
'smtp_configured' => $smtpConfigured,
'recovery_codes' => $user->two_factor_recovery_codes
? json_decode($user->two_factor_recovery_codes, true)
: [],
],