Passed
Push — master ( b0761f...1fb147 )
by Anton
03:12 queued 11s
created

AuthController::token()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\App\Controller;
13
14
use Spiral\Auth\AuthContextInterface;
15
use Spiral\Auth\TokenStorageInterface;
16
use Spiral\Core\Exception\ControllerException;
17
use Spiral\Security\GuardInterface;
18
19
class AuthController
20
{
21
    public function do(GuardInterface $guard)
22
    {
23
        if (!$guard->allows('do')) {
24
            throw new ControllerException("Unauthorized permission 'do'", ControllerException::FORBIDDEN);
25
        }
26
27
        return 'ok';
28
    }
29
30
    public function token(AuthContextInterface $authContext)
31
    {
32
        if ($authContext->getToken() !== null) {
33
            return $authContext->getToken()->getID();
34
        }
35
36
        return 'none';
37
    }
38
39
    public function login(AuthContextInterface $authContext, TokenStorageInterface $tokenStorage)
40
    {
41
        $authContext->start(
42
            $tokenStorage->create(['userID' => 1])
43
        );
44
45
        return 'OK';
46
    }
47
}
48