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

AuthApiAction::performChecks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 3
eloc 10
nc 3
nop 0
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
}