function drupalchat_user_logout in DrupalChat 8
Same name and namespace in other branches
- 7.2 drupalchat.module \drupalchat_user_logout()
- 7 drupalchat.module \drupalchat_user_logout()
Implements hook_user_logout
File
- ./
drupalchat.module, line 61 - Module code for DrupalChat.
Code
function drupalchat_user_logout($account) {
$polling_method = \Drupal::config('drupalchat.settings')
->get('drupalchat_polling_method') ?: DRUPALCHAT_AJAX;
if ($polling_method == DRUPALCHAT_COMMERCIAL) {
setcookie("iflychat_key", "", time() - 3600, "/");
setcookie("iflychat_css", "", time() - 3600, "/");
setcookie("iflychat_time", "", time() - 3600, "/");
}
$url = DRUPALCHAT_EXTERNAL_A_HOST . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/api/1.1/token/generate';
$client = \Drupal::httpClient();
try {
$request = $client
->post($url, [
'verify' => false,
'form_params' => [
'api_key' => \Drupal::config('drupalchat.settings')
->get('drupalchat_external_api_key') ?: NULL,
],
]);
} catch (BadResponseException $exception) {
$e = array(
'code' => $exception
->getResponse()
->getStatusCode(),
'error' => $exception
->getResponse()
->getReasonPhrase(),
);
return $e;
} catch (RequestException $exception) {
$e = array(
'code' => $exception
->getResponse()
->getStatusCode(),
'error' => $exception
->getResponse()
->getReasonPhrase(),
);
return $e;
}
if (json_decode($request
->getStatusCode()) == 200) {
$response = json_decode($request
->getBody());
unset($_SESSION['token']);
return $response;
}
}