Skip to content

Commit 16f2829

Browse files
authored
Merge branch 'main' into main
2 parents 4b47a71 + fef21e3 commit 16f2829

File tree

9 files changed

+58
-9
lines changed

9 files changed

+58
-9
lines changed

.github/workflows/phpstan.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
paths:
66
- '**.php'
77
- '.github/workflows/phpstan.yml'
8-
- 'phpstan.neon.dist'
8+
- 'phpstan.neon'
9+
- 'phpstan.laravel-10.neon'
910
pull_request:
1011
branches:
1112
- '**'
@@ -23,8 +24,10 @@ jobs:
2324
include:
2425
- laravel: 10.*
2526
testbench: 8.*
27+
phpstan_neon: phpstan.laravel-10.neon
2628
- laravel: 11.*
2729
testbench: 9.*
30+
phpstan_neon: phpstan.neon
2831
exclude:
2932
- laravel: 11.*
3033
php: 8.1
@@ -50,4 +53,4 @@ jobs:
5053
run: composer show -D
5154

5255
- name: Run PHPStan
53-
run: vendor/bin/phpstan --error-format=github
56+
run: vendor/bin/phpstan --error-format=github --configuration=${{ matrix.phpstan_neon }}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to `dutchcodingcompany/developer-logins` will be documented in this file.
44

5+
## 1.3.0 - 2024-10-11
6+
7+
- Catch model-not-found errors + simplify code by @bert-w in https://github.com/DutchCodingCompany/filament-developer-logins/pull/10
8+
- Fix: Clear session password hash to resolve "Switch To" Button Error (Issue #15) by @slimani-dev in https://github.com/DutchCodingCompany/filament-developer-logins/pull/17
9+
510
## 1.2.1 - 2024-06-19
611

712
- Bugfix: Plugin issue with multiple panels by @ainesophaur in https://github.com/DutchCodingCompany/filament-developer-logins/pull/9

phpstan-baseline.neon

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ parameters:
1111
path: src/FilamentDeveloperLoginsPlugin.php
1212

1313
-
14-
message: "#^Call to an undefined method object\\:\\:where\\(\\)\\.$#"
14+
message: "#^Property DutchCodingCompany\\\\FilamentDeveloperLogins\\\\FilamentDeveloperLoginsPlugin\\:\\:\\$modelClass \\(class\\-string\\<Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable&Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\) does not accept default value of type string\\.$#"
1515
count: 1
16-
path: src/FilamentDevelopersLogin.php
16+
path: src/FilamentDeveloperLoginsPlugin.php
1717

1818
-
19-
message: "#^Call to an undefined method Livewire\\\\Features\\\\SupportTesting\\\\Testable\\:\\:test\\(\\)\\.$#"
19+
message: "#^Call to an undefined method Illuminate\\\\Testing\\\\TestResponse\\:\\:assertDontSeeLivewire\\(\\)\\.$#"
2020
count: 3
2121
path: tests/Feature/MenuLoginsTest.php
2222

23+
-
24+
message: "#^Call to an undefined method Illuminate\\\\Testing\\\\TestResponse\\:\\:assertSeeLivewire\\(\\)\\.$#"
25+
count: 2
26+
path: tests/Feature/MenuLoginsTest.php
27+
2328
-
2429
message: "#^Access to an undefined property DutchCodingCompany\\\\FilamentDeveloperLogins\\\\Tests\\\\Fixtures\\\\TestUser\\:\\:\\$is_admin\\.$#"
2530
count: 1

phpstan.laravel-10.neon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
includes:
2+
- ./vendor/larastan/larastan/extension.neon
3+
- phpstan-baseline.neon
4+
5+
parameters:
6+
level: 7
7+
8+
paths:
9+
- database
10+
- src
11+
- tests
12+
13+
ignoreErrors:
14+
-
15+
message: "#^PHPDoc tag @use contains generic type Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\HasFactory\\<DutchCodingCompany\\\\FilamentDeveloperLogins\\\\Database\\\\Factories\\\\TestUserFactory\\> but trait Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\HasFactory is not generic\\.$#"
16+
count: 1
17+
path: tests/Fixtures/TestUser.php

resources/lang/en/auth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
'messages' => [
88
'failed' => 'Login failed, check if the user is allowed to access the panel.',
9+
'failed_not_found' => 'Login failed, the user cannot be found.',
910
],
1011
];

resources/views/components/developer-logins.blade.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
:attributes="\Filament\Support\prepare_inherited_attributes($attributes)->class('fi-wi gap-4')"
2828
>
2929
@foreach ($users as $label => $credentials)
30-
@if ($loop->first)
31-
@endif
3230
<form action="{{ route('filament-developer-logins.login-as') }}" method="POST">
3331
@csrf
3432

@@ -42,4 +40,4 @@
4240
@endforeach
4341
</x-filament::grid>
4442
</div>
45-
@endif
43+
@endif

src/FilamentDeveloperLoginsPlugin.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class FilamentDeveloperLoginsPlugin implements Plugin
3131

3232
public string $column = 'email';
3333

34+
/**
35+
* @var class-string<\Illuminate\Database\Eloquent\Model&\Illuminate\Contracts\Auth\Authenticatable>
36+
*/
3437
public string $modelClass = User::class;
3538

3639
public function getId(): string
@@ -145,6 +148,9 @@ public function getColumn(): string
145148
return $this->column;
146149
}
147150

151+
/**
152+
* @param class-string<\Illuminate\Database\Eloquent\Model&\Illuminate\Contracts\Auth\Authenticatable> $modelClass
153+
*/
148154
public function modelClass(string $modelClass): static
149155
{
150156
if (! is_a($modelClass, Authenticatable::class, true)) {
@@ -156,6 +162,9 @@ public function modelClass(string $modelClass): static
156162
return $this;
157163
}
158164

165+
/**
166+
* @return class-string<\Illuminate\Database\Eloquent\Model&\Illuminate\Contracts\Auth\Authenticatable>
167+
*/
159168
public function getModelClass(): string
160169
{
161170
return $this->modelClass;

src/FilamentDevelopersLogin.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ public function login(Panel $panel, FilamentDeveloperLoginsPlugin $plugin, strin
1919

2020
if ($panel->auth()->check()) {
2121
$panel->auth()->logout();
22+
2223
session()->forget('password_hash_'.$panel->getAuthGuard());
2324
}
2425

26+
/** @var ?\Illuminate\Contracts\Auth\Authenticatable $model */
2527
$model = (new ($plugin->getModelClass()))
2628
->where($plugin->getColumn(), $credentials)
27-
->firstOrFail();
29+
->first();
30+
31+
if (! $model) {
32+
throw ValidationException::withMessages([
33+
'developer-logins-failed' => __('filament-developer-logins::auth.messages.failed_not_found'),
34+
]);
35+
}
2836

2937
$panel->auth()->login($model);
3038

tests/Fixtures/TestUser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
class TestUser extends Model implements Authenticatable, FilamentUser
1212
{
13+
/**
14+
* @use \Illuminate\Database\Eloquent\Factories\HasFactory<\DutchCodingCompany\FilamentDeveloperLogins\Database\Factories\TestUserFactory>
15+
*/
1316
use HasFactory;
1417

1518
protected $table = 'users';

0 commit comments

Comments
 (0)