UserChecker::checkPostAuth()   B
last analyzed

Complexity

Conditions 9
Paths 6

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 16.1088

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 10
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 20
ccs 5
cts 9
cp 0.5556
crap 16.1088
rs 8.0555
1
<?php
2
3
namespace App\Security;
4
5
use App\Entity\User;
6
use App\Security\EmailConfirmation\ConfirmationManager;
7
use SchulIT\CommonBundle\Helper\DateHelper;
8
use Symfony\Component\Security\Core\User\UserCheckerInterface;
9
use Symfony\Component\Security\Core\User\UserInterface;
10
11
class UserChecker implements UserCheckerInterface {
12
13
    public function __construct(private DateHelper $dateHelper)
14
    {
15
    }
16 16
17 16
    /**
18 16
     * @inheritDoc
19 16
     */
20
    public function checkPreAuth(UserInterface $user) { }
21
22
    /**
23
     * @inheritDoc
24
     */
25
    public function checkPostAuth(UserInterface $user) {
26
        if(!$user instanceof User) {
27
            return;
28
        }
29 13
30 13
        // First check: is the user account marked "active"?
31
        if($user->isActive() !== true) {
32
            throw new AccountDisabledException();
33
        }
34
35 13
        // Second check: does the user has a time window in which the account is active?
36 1
        if($user->getEnabledFrom() !== null || $user->getEnabledUntil() !== null) {
37
            $today = $this->dateHelper->getToday();
38
39 12
            if($user->getEnabledFrom() !== null && $user->getEnabledFrom() > $today) {
40
                throw new AccountDisabledException();
41
            }
42
43
            if($user->getEnabledUntil() !== null && $user->getEnabledUntil() < $today) {
44
                throw new AccountDisabledException();
45
            }
46
        }
47
    }
48
}