47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use App\Models\AuditEvent;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
/**
|
|
* Backup (recovery) codes, shown once in a modal. Opened on first-factor enrollment and
|
|
* from Settings → Security ("Backup-Codes verwalten"). The download endpoint stays a route.
|
|
*/
|
|
class RecoveryCodes extends ModalComponent
|
|
{
|
|
public static function modalMaxWidth(): string
|
|
{
|
|
return 'lg';
|
|
}
|
|
|
|
/** @return array<int, string> */
|
|
public function codes(): array
|
|
{
|
|
return Auth::user()->recoveryCodes();
|
|
}
|
|
|
|
/** Regenerate the current user's backup codes (invalidates the old set). */
|
|
public function regenerate(): void
|
|
{
|
|
Auth::user()->replaceRecoveryCodes();
|
|
|
|
AuditEvent::create([
|
|
'user_id' => Auth::id(),
|
|
'actor' => Auth::user()->name ?? 'system',
|
|
'action' => 'two_factor.recovery_regenerate',
|
|
'target' => Auth::user()->email,
|
|
'ip' => request()->ip(),
|
|
]);
|
|
|
|
$this->dispatch('notify', message: __('auth.recovery_regenerated'));
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.modals.recovery-codes', ['codes' => $this->codes()]);
|
|
}
|
|
}
|