feat: add global toggles for TOTP and Email 2FA in system settings, conditionally show/hide user 2FA tab
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user