mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-06 08:22:34 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -54,7 +54,7 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->label('Password')
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
->action(function (array $data): void {
|
||||
self::logoutOtherBrowserSessions($data['password']);
|
||||
})
|
||||
->modalWidth('2xl'),
|
||||
@ -62,6 +62,9 @@ public function infolist(Infolist $infolist): Infolist
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
private function getDynamicSchema(): array
|
||||
{
|
||||
$sections = [];
|
||||
@ -71,8 +74,8 @@ private function getDynamicSchema(): array
|
||||
->schema([
|
||||
TextEntry::make('device')
|
||||
->hiddenLabel()
|
||||
->icon($session->device['desktop'] ? 'heroicon-o-computer-desktop' : 'heroicon-o-device-phone-mobile')
|
||||
->state($session->device['platform'].' - '.$session->device['browser']),
|
||||
->icon(isset($session->device['desktop']) ? 'heroicon-o-computer-desktop' : 'heroicon-o-device-phone-mobile')
|
||||
->state(($session->device['platform'] ?? 'Platform').' - '.($session->device['browser'] ?? 'Browser')),
|
||||
TextEntry::make('browser')
|
||||
->hiddenLabel()
|
||||
->icon('heroicon-o-map-pin')
|
||||
@ -92,15 +95,32 @@ private function getDynamicSchema(): array
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, object{
|
||||
* device: array{
|
||||
* browser: string,
|
||||
* desktop: bool,
|
||||
* mobile: bool,
|
||||
* tablet: bool,
|
||||
* platform: string
|
||||
* },
|
||||
* ip_address: string|null,
|
||||
* is_current_device: bool,
|
||||
* last_active: string
|
||||
* }>
|
||||
*/
|
||||
private function getSessions(): array
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
if (config(key: 'session.driver') !== 'database') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect(
|
||||
value: DB::connection(config(key: 'session.connection'))->table(table: config(key: 'session.table', default: 'sessions'))
|
||||
->where(column: 'user_id', operator: Auth::user()->getAuthIdentifier())
|
||||
->where(column: 'user_id', operator: $user->getAuthIdentifier())
|
||||
->latest(column: 'last_activity')
|
||||
->get()
|
||||
)->map(callback: function ($session): object {
|
||||
@ -121,17 +141,20 @@ private function getSessions(): array
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
private function createAgent(mixed $session)
|
||||
private function createAgent(mixed $session): Agent
|
||||
{
|
||||
return tap(
|
||||
value: new Agent,
|
||||
callback: fn ($agent) => $agent->setUserAgent(userAgent: $session->user_agent)
|
||||
callback: fn ($agent): string => $agent->setUserAgent(userAgent: $session->user_agent)
|
||||
);
|
||||
}
|
||||
|
||||
private function logoutOtherBrowserSessions($password): void
|
||||
private function logoutOtherBrowserSessions(string $password): void
|
||||
{
|
||||
if (! Hash::check($password, Auth::user()->password)) {
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
if (! Hash::check($password, $user->password)) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('The password you entered was incorrect. Please try again.')
|
||||
@ -143,7 +166,7 @@ private function logoutOtherBrowserSessions($password): void
|
||||
Auth::guard()->logoutOtherDevices($password);
|
||||
|
||||
request()->session()->put([
|
||||
'password_hash_'.Auth::getDefaultDriver() => Auth::user()->getAuthPassword(),
|
||||
'password_hash_'.Auth::getDefaultDriver() => $user->getAuthPassword(),
|
||||
]);
|
||||
|
||||
$this->deleteOtherSessionRecords();
|
||||
@ -156,12 +179,15 @@ private function logoutOtherBrowserSessions($password): void
|
||||
|
||||
private function deleteOtherSessionRecords(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
if (config(key: 'session.driver') !== 'database') {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::connection(config(key: 'session.connection'))->table(table: config(key: 'session.table', default: 'sessions'))
|
||||
->where('user_id', Auth::user()->getAuthIdentifier())
|
||||
->where('user_id', $user->getAuthIdentifier())
|
||||
->where('id', '!=', request()->session()->getId())
|
||||
->delete();
|
||||
}
|
||||
|
@ -29,14 +29,19 @@ class ProfileInformation extends Widget implements HasForms
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->name = auth()->user()->name;
|
||||
$this->email = auth()->user()->email;
|
||||
$this->timezone = auth()->user()->timezone;
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
$this->name = $user->name;
|
||||
$this->email = $user->email;
|
||||
$this->timezone = $user->timezone;
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
$rules = UpdateUserProfileInformation::rules(auth()->user());
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$rules = UpdateUserProfileInformation::rules($user);
|
||||
|
||||
return $form
|
||||
->schema([
|
||||
@ -69,9 +74,12 @@ public function form(Form $form): Form
|
||||
|
||||
public function submit(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$this->validate();
|
||||
|
||||
app(UpdateUserProfileInformation::class)->update(auth()->user(), $this->all());
|
||||
app(UpdateUserProfileInformation::class)->update($user, $this->all());
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
|
@ -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