feat: add global toggles for TOTP and Email 2FA in system settings, conditionally show/hide user 2FA tab

This commit is contained in:
2026-05-21 22:05:14 +07:00
parent 6c582282ac
commit 1a30122c3d
41 changed files with 348 additions and 285 deletions
+23 -3
View File
@@ -48,10 +48,30 @@ class SettingsController extends Controller
$smtpConfigured = !empty($mailHost) && !empty($mailUsername) && !empty($mailPassword);
}
$totpAllowed = true;
$emailAllowed = true;
try {
$systemSettings = \Illuminate\Support\Facades\Cache::rememberForever('system_settings', function () {
return \App\Models\Setting::all()->pluck('value', 'key')->toArray();
});
if (isset($systemSettings['two_factor_totp_enabled'])) {
$totpAllowed = $systemSettings['two_factor_totp_enabled'] === '1' || $systemSettings['two_factor_totp_enabled'] === true;
}
if (isset($systemSettings['two_factor_email_enabled'])) {
$emailAllowed = $systemSettings['two_factor_email_enabled'] === '1' || $systemSettings['two_factor_email_enabled'] === true;
}
} catch (\Exception $e) {
// DB not ready or migrated
}
return Inertia::render('Settings/Index', [
'mustVerifyEmail' => $user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail,
'status' => session('status'),
'twoFactor' => [
'mustVerifyEmail' => $user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail,
'status' => session('status'),
'twoFactorSettings' => [
'totp_allowed' => $totpAllowed,
'email_allowed' => $emailAllowed,
],
'twoFactor' => [
'enabled' => $twoFactorEnabled,
'qr_code' => $qrCode,
'secret' => $secret,