]> Raphaël G. Git Repositories - userbundle/blob - Checker/UserChecker.php
Version 0.5.8
[userbundle] / Checker / UserChecker.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys UserBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\UserBundle\Checker;
13
14 use Rapsys\UserBundle\Entity\User;
15 use Rapsys\UserBundle\Exception\UnactivatedException;
16
17 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
18 use Symfony\Component\Security\Core\Exception\DisabledException;
19 use Symfony\Component\Security\Core\User\InMemoryUserChecker;
20 use Symfony\Component\Security\Core\User\UserInterface;
21
22 /**
23 * {@inheritdoc}
24 */
25 class UserChecker extends InMemoryUserChecker {
26 /**
27 * {@inheritdoc}
28 */
29 public function checkPostAuth(UserInterface $user, ?TokenInterface $token = null): void {
30 //Without User instance
31 if (!$user instanceof User) {
32 return;
33 }
34
35 //With not activated user
36 if (!$user->isActivated()) {
37 $ex = new UnactivatedException('User Account is not activated');
38 $ex->setUser($user);
39 throw $ex;
40 }
41
42 //With not enabled user
43 if (!$user->isEnabled()) {
44 $ex = new DisabledException('User account is not enabled');
45 $ex->setUser($user);
46 throw $ex;
47 }
48
49 //Call parent checkPreAuth
50 parent::checkPostAuth($user);
51 }
52 }