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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user