|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Daniel West <[email protected]> |
|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Security; |
|
15
|
|
|
|
|
16
|
|
|
use Silverback\ApiComponentsBundle\Entity\User\AbstractUser; |
|
17
|
|
|
use Silverback\ApiComponentsBundle\Exception\UserDisabledException; |
|
18
|
|
|
use Silverback\ApiComponentsBundle\Exception\UserEmailAddressUnverified; |
|
19
|
|
|
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException; |
|
20
|
|
|
use Symfony\Component\Security\Core\User\UserCheckerInterface; |
|
21
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
22
|
|
|
|
|
23
|
|
|
class UserChecker implements UserCheckerInterface |
|
24
|
|
|
{ |
|
25
|
|
|
private bool $denyUnverifiedLogin; |
|
26
|
|
|
|
|
27
|
5 |
|
public function __construct(bool $denyUnverifiedLogin = true) |
|
28
|
|
|
{ |
|
29
|
5 |
|
$this->denyUnverifiedLogin = $denyUnverifiedLogin; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
4 |
|
public function checkPreAuth(UserInterface $user): void |
|
33
|
|
|
{ |
|
34
|
4 |
|
if (!$user instanceof AbstractUser) { |
|
35
|
1 |
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
3 |
|
if (!$user->isEnabled()) { |
|
39
|
1 |
|
$message = 'Your account is currently disabled.'; |
|
40
|
1 |
|
if (class_exists(CustomUserMessageAccountStatusException::class)) { |
|
41
|
1 |
|
throw new CustomUserMessageAccountStatusException($message); |
|
42
|
|
|
} |
|
43
|
|
|
throw new UserDisabledException($message); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
2 |
|
if ($this->denyUnverifiedLogin && !$user->isEmailAddressVerified()) { |
|
47
|
1 |
|
$message = 'Please verify your email address before logging in. If you did not receive a confirmation email please try resetting your password using the forgot password feature.'; |
|
48
|
1 |
|
if (class_exists(CustomUserMessageAccountStatusException::class)) { |
|
49
|
1 |
|
throw new CustomUserMessageAccountStatusException($message); |
|
50
|
|
|
} |
|
51
|
|
|
throw new UserEmailAddressUnverified($message); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
public function checkPostAuth(UserInterface $user): void |
|
56
|
|
|
{ |
|
57
|
1 |
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|