. */ declare(strict_types=1); namespace App\Security; use App\Entity\UserSystem\User; use Symfony\Component\Security\Core\Exception\AccountStatusException; use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException; use Symfony\Component\Security\Core\User\UserCheckerInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Contracts\Translation\TranslatorInterface; /** * @see \App\Tests\Security\UserCheckerTest */ final class UserChecker implements UserCheckerInterface { public function __construct(private readonly TranslatorInterface $translator) { } /** * Checks the user account before authentication. * * @throws AccountStatusException */ public function checkPreAuth(UserInterface $user): void { // TODO: Implement checkPreAuth() method. } /** * Checks the user account after authentication. * * @throws AccountStatusException */ public function checkPostAuth(UserInterface $user): void { if (!$user instanceof User) { return; } //Check if user is disabled. Then don't allow login if ($user->isDisabled()) { //throw new DisabledException(); throw new CustomUserMessageAccountStatusException($this->translator->trans('user.login_error.user_disabled', [], 'security')); } } }