You are here

function cas_server_logout_clients in CAS 6.3

Same name and namespace in other branches
  1. 7 cas_server.module \cas_server_logout_clients()

Send CAS a logout requests for each of the user's CAS tickets.

Parameters

$account: The user for whom to send CAS logout requests.

1 call to cas_server_logout_clients()
cas_server_user in ./cas_server.module
Implements hook_user().

File

./cas_server.module, line 268
Provides a protocol compliant version of CAS server 2.x

Code

function cas_server_logout_clients($account) {
  $result = db_query("SELECT service, ticket, valid FROM {cas_server_tickets} WHERE uid=%d", array(
    $account->uid,
  ));
  $expired_tickets = array();
  while ($client = db_fetch_object($result)) {
    $expired_tickets[] = $client->ticket;
    if (!$client->valid) {
      $id = 'LR-' . user_password();
      $date = date('c');
      $logout_request = theme('cas_service_logout_request', $client->ticket, $date, $id);

      // Send POST request
      $response = drupal_http_request($client->service, array(
        'Content-Type' => 'application/x-www-form-urlencoded',
      ), 'POST', 'logoutRequest=' . urlencode($logout_request));
      if (@$response->error) {
        watchdog('error', 'Error in CAS logout Request - %code : %message', array(
          '%code' => $response->code,
          '%error' => $response->error,
        ));
      }
    }
  }
  if ($expired_tickets) {
    db_query("DELETE FROM {cas_server_tickets} WHERE ticket IN (" . db_placeholders($expired_tickets, 'int') . ")", $expired_tickets);
  }
}