]> Raphaël G. Git Repositories - userbundle/blob - Checker/UserChecker.php
Strict types
[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 Symfony\Component\Security\Core\User\InMemoryUserChecker;
15 use Symfony\Component\Security\Core\Exception\DisabledException;
16 use Symfony\Component\Security\Core\User\UserInterface;
17
18 use Rapsys\UserBundle\Entity\User;
19 use Rapsys\UserBundle\Exception\UnactivatedException;
20
21 /**
22 * {@inheritdoc}
23 */
24 class UserChecker extends InMemoryUserChecker {
25 /**
26 * {@inheritdoc}
27 */
28 public function checkPostAuth(UserInterface $user): void {
29 //Without User instance
30 if (!$user instanceof User) {
31 return;
32 }
33
34 //With not activated user
35 if (!$user->isActivated()) {
36 $ex = new UnactivatedException('Account is not activated');
37 $ex->setUser($user);
38 throw $ex;
39 }
40
41 //With disabled user
42 if ($user->isDisabled()) {
43 $ex = new DisabledException('Account is disabled');
44 $ex->setUser($user);
45 throw $ex;
46 }
47 }
48 }