Passed
Push — feature/uploadable ( 7c6d25...a7ed20 )
by Daniel
11:07
created

UserChecker   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A checkPreAuth() 0 12 5
A checkPostAuth() 0 2 1
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 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 3
        if (!$user->isEnabled()) {
37 1
            throw new DisabledException('This user is currently disabled');
38
        }
39
40 2
        if ($this->denyUnverifiedLogin && !$user->isEmailAddressVerified()) {
41 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.');
42
        }
43 1
    }
44
45 1
    public function checkPostAuth(UserInterface $user): void
46
    {
47 1
    }
48
}
49