feat: enforce SMTP configuration validation and show warning notices before enabling Email 2FA
This commit is contained in:
@@ -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)
|
||||
: [],
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user