You are here

function cas_logout in CAS 5.3

Same name and namespace in other branches
  1. 5.4 cas.module \cas_logout()
  2. 5 cas.module \cas_logout()
  3. 6.3 cas.module \cas_logout()
  4. 6 cas.module \cas_logout()
  5. 6.2 cas.module \cas_logout()
  6. 7 cas.module \cas_logout()

Logs a user out of drupal and then out of cas

1 string reference to 'cas_logout'
cas_menu in ./cas.module
Implements hook_menu.

File

./cas.module, line 727

Code

function cas_logout() {
  global $user;
  watchdog('user', 'Session closed for %name.', array(
    '%name' => $user->name,
  ));

  // Destroy the current session:
  session_destroy();
  module_invoke_all('user', 'logout', NULL, $user);

  // We have to use $GLOBALS to unset a global variable:
  $user = user_load(array(
    'uid' => 0,
  ));
  $port = variable_get('cas_port', '443');
  $server = variable_get('cas_server', 'cas');
  $uri = variable_get('cas_uri', '');

  // Begin constructing logout destination
  $logout_destination = 'https://' . $server;

  // Add abnormal port
  if ($port != '443') {
    $logout_destination .= ':' . $port;
  }

  // Add logout
  if ($uri) {
    $logout_destination .= '/' . trim($uri, '/');
  }
  $logout_destination .= '/logout';

  // Add destination override so that a destination can be specified on the logout link
  // e.g. caslogout?desination=http://foo.bar.com/foobar
  // do not accept caslogout as a valid destination, since that may cause a redirect loop
  $destination = preg_replace("/(destination=|caslogout)/", "", drupal_get_destination());

  //Make it an absolute url.  This will also convert <front> to the front page.
  $destination = url($destination, null, null, TRUE);

  // If there was no override and admin has set and enabled a logout destination, look for it
  if (empty($destination) && variable_get('cas_logout_redirect', 0)) {
    $destination = variable_get('cas_logout_destination', '');

    // redirecti is enabled but no url is given - default to baseurl
    if (empty($destination)) {
      $destination = $base_url;
    }
  }

  // Add the log out destination if we have one
  // The three variables are a hack because cas server implementations don't seem to be consistent with
  // its use.
  if ($destination) {
    $logout_destination .= '?destination=' . $destination . '&service=' . $destination . '&url=' . $destination;
  }

  // Go to the constructed logout destination
  drupal_goto($logout_destination);
}