Conditions | 3 |
Paths | 3 |
Total Lines | 26 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
42 | public function handle($event) |
||
43 | { |
||
44 | if (!$event->user) { |
||
45 | return; |
||
46 | } |
||
47 | |||
48 | $configs = [ |
||
49 | 'base_uri' => config('services.discourse.url'), |
||
|
|||
50 | 'headers' => [ |
||
51 | 'Api-Key' => config('services.discourse.api.key'), |
||
52 | 'Api-Username' => config('services.discourse.api.user'), |
||
53 | ], |
||
54 | ]; |
||
55 | |||
56 | // Get Discourse user to match this one, and send a Logout request to Discourse and get the response |
||
57 | $user = json_decode( |
||
58 | $this->client->get("users/by-external/{$event->user->id}.json", $configs) |
||
59 | ->getBody() |
||
60 | )->user; |
||
61 | |||
62 | $response = $this->client->post("admin/users/{$user->id}/log_out"); |
||
63 | |||
64 | if ($response->getStatusCode() !== 200) { |
||
65 | Log::notice( |
||
66 | "When logging out user {$event->user->id} Discourse returned status code {$response->getStatusCode()}:", |
||
67 | ['reason' => $response->getReasonPhrase()] |
||
68 | ); |
||
72 |