X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/userbundle/blobdiff_plain/c2a35920b8751374e24723703026f57a62ef41b6..HEAD:/Checker/UserChecker.php diff --git a/Checker/UserChecker.php b/Checker/UserChecker.php index e34284e..51b6fa9 100644 --- a/Checker/UserChecker.php +++ b/Checker/UserChecker.php @@ -11,13 +11,14 @@ namespace Rapsys\UserBundle\Checker; -use Symfony\Component\Security\Core\User\InMemoryUserChecker; -use Symfony\Component\Security\Core\Exception\DisabledException; -use Symfony\Component\Security\Core\User\UserInterface; - use Rapsys\UserBundle\Entity\User; use Rapsys\UserBundle\Exception\UnactivatedException; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Exception\DisabledException; +use Symfony\Component\Security\Core\User\InMemoryUserChecker; +use Symfony\Component\Security\Core\User\UserInterface; + /** * {@inheritdoc} */ @@ -25,24 +26,27 @@ class UserChecker extends InMemoryUserChecker { /** * {@inheritdoc} */ - public function checkPostAuth(UserInterface $user): void { + public function checkPostAuth(UserInterface $user, ?TokenInterface $token = null): void { //Without User instance if (!$user instanceof User) { return; } //With not activated user - if (!$user->isActivated()) { - $ex = new UnactivatedException('Account is not activated'); - $ex->setUser($user); - throw $ex; - } - - //With disabled user - if ($user->isDisabled()) { - $ex = new DisabledException('Account is disabled'); - $ex->setUser($user); - throw $ex; - } + if (!$user->isActivated()) { + $ex = new UnactivatedException('User Account is not activated'); + $ex->setUser($user); + throw $ex; + } + + //With not enabled user + if (!$user->isEnabled()) { + $ex = new DisabledException('User account is not enabled'); + $ex->setUser($user); + throw $ex; + } + + //Call parent checkPreAuth + parent::checkPostAuth($user); } }