Completed
Push — master ( c44596...d67676 )
by Vincenzo
01:55
created

AuthApiAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A performChecks() 0 18 3
1
<?php
2
3
4
namespace App\Actions\Base;
5
6
7
use App\Lib\Helpers\Config;
8
use App\Lib\Slime\Exceptions\Http\UnAuthorizedException;
9
use App\Lib\Slime\RestAction\ApiAction;
10
use App\Models\Users\UserToken;
11
12
abstract class AuthApiAction extends ApiAction
13
{
14
    protected $userId;
15
16
    protected function performChecks()
17
    {
18
        $token = $this->request->getHeader(
19
            Config::get('app.authHeader')
20
        );
21
        if (empty($token)) {
22
            throw new UnAuthorizedException('Missing Header');
23
        }
24
25
        $this->userId = UserToken::getValidUserId(
26
            $token,
27
            $this->request->getAttribute('ip_address')
28
        );
29
        if (empty($this->userId)) {
30
            // Log attempt then remove token?
31
            throw new UnAuthorizedException('Unauthorized');
32
        }
33
    }
34
35
}