user disabled_at field addedù
This commit is contained in:
32
backend/app/Actions/Fortify/AuthenticateUser.php
Normal file
32
backend/app/Actions/Fortify/AuthenticateUser.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Laravel\Fortify\Fortify;
|
||||
|
||||
/**
|
||||
* Login custom: oltre a verificare le credenziali, blocca gli utenti con
|
||||
* `disabled_at` impostato (es. legacy `is_active=false`). I soft-deleted sono
|
||||
* già esclusi dalla query di default (scope SoftDeletes sul model User), non
|
||||
* serve un controllo esplicito.
|
||||
*
|
||||
* Registrata via `Fortify::authenticateUsing()`: viene consultata sia dal
|
||||
* pre-check 2FA (`RedirectIfTwoFactorAuthenticatable`) sia dal fallback
|
||||
* (`AttemptToAuthenticate`), quindi un solo punto di applicazione del gate.
|
||||
*/
|
||||
class AuthenticateUser
|
||||
{
|
||||
public function __invoke(Request $request): ?User
|
||||
{
|
||||
$user = User::where(Fortify::username(), $request->input(Fortify::username()))->first();
|
||||
|
||||
if (! $user || ! Hash::check((string) $request->input('password'), $user->password)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $user->disabled_at === null ? $user : null;
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ class User extends Authenticatable implements Auditable, MustVerifyEmail
|
||||
'two_factor_confirmed_at' => 'datetime',
|
||||
'is_system' => 'boolean',
|
||||
'anonymized_at' => 'datetime',
|
||||
'disabled_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Actions\Fortify\AuthenticateUser;
|
||||
use App\Actions\Fortify\CreateNewUser;
|
||||
use App\Actions\Fortify\ResetUserPassword;
|
||||
use App\Actions\Fortify\UpdateUserPassword;
|
||||
@@ -29,6 +30,7 @@ class FortifyServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Fortify::authenticateUsing(new AuthenticateUser);
|
||||
Fortify::createUsersUsing(CreateNewUser::class);
|
||||
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
|
||||
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
|
||||
|
||||
Reference in New Issue
Block a user