50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Settings;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
class Security extends Component
|
|
{
|
|
public function confirmDisableTwoFactor(): void
|
|
{
|
|
$this->dispatch('openModal',
|
|
component: 'modals.confirm-action',
|
|
arguments: [
|
|
'heading' => __('settings.disable_2fa_heading'),
|
|
'body' => __('settings.disable_2fa_body'),
|
|
'confirmLabel' => __('common.disable'),
|
|
'danger' => true,
|
|
'icon' => 'shield',
|
|
'auditAction' => 'two_factor.disable',
|
|
'auditTarget' => Auth::user()?->email,
|
|
'event' => 'twoFactorDisabled',
|
|
'notify' => __('settings.disable_2fa_notify'),
|
|
],
|
|
);
|
|
}
|
|
|
|
#[On('twoFactorDisabled')]
|
|
public function disableTwoFactor(): void
|
|
{
|
|
// Remove the TOTP factor only — security keys are managed on their own card. If no
|
|
// factor remains afterwards, the backup codes are dropped too.
|
|
Auth::user()->forceFill([
|
|
'two_factor_secret' => null,
|
|
'two_factor_confirmed_at' => null,
|
|
])->save();
|
|
|
|
Auth::user()->resetIfNoFactor();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.settings.security', [
|
|
'twoFactorEnabled' => Auth::user()->hasTwoFactorEnabled(),
|
|
'hasTotp' => Auth::user()->hasTotp(),
|
|
]);
|
|
}
|
|
}
|