Conditions | 5 |
Paths | 1 |
Total Lines | 33 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 8.7091 |
Changes | 0 |
1 | <?php |
||
29 | 2 | public function call(Micro $api) |
|
30 | { |
||
31 | 2 | $auth = $api->getService('auth'); |
|
32 | 2 | $config = $api->getService('config'); |
|
33 | |||
34 | // to get the payload |
||
35 | 2 | $data = $auth->data(); |
|
36 | |||
37 | 2 | $api->getDI()->setShared( |
|
38 | 2 | 'userData', |
|
39 | function () use ($config, $data) { |
||
40 | $session = new Sessions(); |
||
41 | $request = new Request(); |
||
42 | |||
43 | //dev? |
||
44 | if (strtolower($config->app->env) == Flags::DEVELOPMENT) { |
||
45 | return Users::findFirst(1); |
||
46 | } |
||
47 | |||
48 | if (!empty($data) && !empty($data['sessionId'])) { |
||
49 | //user |
||
50 | if (!$user = Users::getByEmail($data['email'])) { |
||
51 | throw new UnauthorizedHttpException('User not found'); |
||
52 | } |
||
53 | |||
54 | return $session->check($user, $data['sessionId'], $request->getClientAddress(), 1); |
||
55 | } else { |
||
56 | throw new UnauthorizedHttpException('User not found'); |
||
57 | } |
||
58 | 2 | } |
|
59 | ); |
||
60 | |||
61 | 2 | return true; |
|
62 | } |
||
64 |