mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -22,6 +22,9 @@ class TwoFactor extends Widget implements HasForms, HasInfolists
|
||||
use InteractsWithForms;
|
||||
use InteractsWithInfolists;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
protected static bool $isLazy = false;
|
||||
@ -34,13 +37,19 @@ class TwoFactor extends Widget implements HasForms, HasInfolists
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
if (auth()->user()->two_factor_secret) {
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->two_factor_secret) {
|
||||
$this->enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $infolist->schema([
|
||||
Section::make()
|
||||
->heading('Two Factor Authentication')
|
||||
@ -53,12 +62,12 @@ public function infolist(Infolist $infolist): Infolist
|
||||
ViewEntry::make('qr_code')
|
||||
->hiddenLabel()
|
||||
->view('components.container', [
|
||||
'content' => $this->enabled ? auth()->user()->twoFactorQrCodeSvg() : null,
|
||||
'content' => $this->enabled ? $user->twoFactorQrCodeSvg() : null,
|
||||
])
|
||||
->visible($this->enabled && $this->showCodes),
|
||||
TextEntry::make('qr_code_manual')
|
||||
->label('If you are unable to scan the QR code, please use the 2FA secret instead.')
|
||||
->state($this->enabled ? decrypt(auth()->user()->two_factor_secret) : null)
|
||||
->state($this->enabled ? decrypt($user->two_factor_secret) : null)
|
||||
->copyable()
|
||||
->visible($this->enabled && $this->showCodes),
|
||||
TextEntry::make('recovery_codes_text')
|
||||
@ -70,7 +79,7 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->hiddenLabel()
|
||||
->extraAttributes(['class' => 'rounded-lg border border-gray-100 p-2 dark:border-gray-700'])
|
||||
->view('components.container', [
|
||||
'content' => $this->enabled ? implode('</br>', json_decode(decrypt(auth()->user()->two_factor_recovery_codes), true)) : null,
|
||||
'content' => $this->enabled ? implode('</br>', json_decode((string) decrypt($user->two_factor_recovery_codes), true)) : null,
|
||||
])
|
||||
->visible($this->enabled),
|
||||
])
|
||||
@ -78,7 +87,7 @@ public function infolist(Infolist $infolist): Infolist
|
||||
Action::make('two-factor')
|
||||
->color($this->enabled ? 'danger' : 'primary')
|
||||
->label($this->enabled ? 'Disable' : 'Enable')
|
||||
->action(function () {
|
||||
->action(function (): void {
|
||||
if ($this->enabled) {
|
||||
$this->disableTwoFactor();
|
||||
} else {
|
||||
@ -96,7 +105,10 @@ public function infolist(Infolist $infolist): Infolist
|
||||
|
||||
public function enableTwoFactor(): void
|
||||
{
|
||||
app(EnableTwoFactorAuthentication::class)(auth()->user());
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
app(EnableTwoFactorAuthentication::class)($user);
|
||||
|
||||
$this->enabled = true;
|
||||
$this->showCodes = true;
|
||||
@ -111,7 +123,10 @@ public function enableTwoFactor(): void
|
||||
|
||||
public function disableTwoFactor(): void
|
||||
{
|
||||
app(DisableTwoFactorAuthentication::class)(auth()->user());
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
app(DisableTwoFactorAuthentication::class)($user);
|
||||
|
||||
$this->enabled = false;
|
||||
$this->showCodes = false;
|
||||
@ -126,7 +141,10 @@ public function disableTwoFactor(): void
|
||||
|
||||
public function regenerateRecoveryCodes(): void
|
||||
{
|
||||
app(GenerateNewRecoveryCodes::class)(auth()->user());
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
app(GenerateNewRecoveryCodes::class)($user);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
|
Reference in New Issue
Block a user