Passed
Push — feature/unit-tests ( 7cf7ac...6c40f3 )
by Daniel
10:30 queued 05:28
created

UserChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component 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\ApiComponentBundle\Security;
15
16
use Silverback\ApiComponentBundle\Entity\User\AbstractUser;
17
use Symfony\Component\Security\Core\Exception\DisabledException;
18
use Symfony\Component\Security\Core\User\UserCheckerInterface;
19
use Symfony\Component\Security\Core\User\UserInterface;
20
21
class UserChecker implements UserCheckerInterface
22
{
23
    private bool $denyUnverifiedLogin;
24
25 5
    public function __construct(bool $denyUnverifiedLogin = true)
26
    {
27 5
        $this->denyUnverifiedLogin = $denyUnverifiedLogin;
28 5
    }
29
30 4
    public function checkPreAuth(UserInterface $user): void
31
    {
32 4
        if (!$user instanceof AbstractUser) {
33 1
            return;
34
        }
35
36
        // user is deleted, show a generic Account Not Found message.
37 3
        if (!$user->isEnabled()) {
38 1
            throw new DisabledException('This user is currently disabled');
39
        }
40
41 2
        if ($this->denyUnverifiedLogin && !$user->isEmailAddressVerified()) {
42 1
            throw new DisabledException('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.');
43
        }
44 1
    }
45
46 1
    public function checkPostAuth(UserInterface $user): void
47
    {
48 1
    }
49
}
50