X-Git-Url: https://git.rapsys.eu/userbundle/blobdiff_plain/436b8a2b29c4df2d84bacfe2acf0545fefd55346..17869e03521ae16d21e3e7d7998ec23fd5da1686:/Checker/UserChecker.php diff --git a/Checker/UserChecker.php b/Checker/UserChecker.php new file mode 100644 index 0000000..1240c8a --- /dev/null +++ b/Checker/UserChecker.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Rapsys\UserBundle\Checker; + +use Symfony\Component\Security\Core\User\UserChecker as BaseUserChecker; +use Symfony\Component\Security\Core\Exception\DisabledException; +use Symfony\Component\Security\Core\User\UserInterface; + +use Rapsys\UserBundle\Entity\User; +use Rapsys\UserBundle\Exception\UnactivatedException; + +/** + * {@inheritdoc} + */ +class UserChecker extends BaseUserChecker { + /** + * {@inheritdoc} + */ + public function checkPostAuth(UserInterface $user): 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; + } + } +}