Conditions | 6 |
Paths | 2 |
Total Lines | 33 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function call(Micro $api) |
||
29 | { |
||
30 | $config = $api->getService('config'); |
||
31 | |||
32 | $auth = $api->getService('auth'); |
||
33 | // to get the payload |
||
34 | $data = $auth->data(); |
||
35 | |||
36 | $api->getDI()->setShared( |
||
37 | 'userData', |
||
38 | function () use ($config, $data) { |
||
39 | $session = new Sessions(); |
||
40 | $request = new Request(); |
||
41 | |||
42 | if (!empty($data) && !empty($data['sessionId'])) { |
||
43 | //user |
||
44 | if (!$user = Users::getByEmail($data['email'])) { |
||
45 | throw new Exception('User not found'); |
||
46 | } |
||
47 | |||
48 | return $session->check($user, $data['sessionId'], $request->getClientAddress(), 1); |
||
49 | } else { |
||
50 | throw new Exception('User not found'); |
||
51 | } |
||
52 | } |
||
53 | ); |
||
54 | |||
55 | if (!empty($data) && $data['iat'] <= strtotime('-10 seconds')) { |
||
56 | // return false to invalidate the authentication |
||
57 | //throw new Exception("Old Request"); |
||
58 | } |
||
59 | |||
60 | return true; |
||
61 | } |
||
63 |