You are here

function cas_logout in CAS 7

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

Logs a user out of Drupal and then out of CAS.

This function does not return, but instead immediately redirects the user to the CAS server to complete the CAS logout process.

Other modules intending to call this from their implementation of hook_user_logout() will need to pass $invoke_hook = FALSE to avoid an infinite recursion. WARNING: since this function does not return, any later implementations of hook_user_logout() will not run. You may wish to adjust the hook execution order using hook_module_implements_alter().

Parameters

$invoke_hook: If TRUE, invoke hook_user_logout() and save a watchdog message indicating that the user has logged out.

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

File

./cas.module, line 705
Enables users to authenticate via a Central Authentication Service (CAS) Cas will currently work if the auto registration is turned on and will create user accounts automatically.

Code

function cas_logout($invoke_hook = TRUE) {
  global $user;

  // Build the logout URL.
  cas_phpcas_init();
  if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {

    // Add destination override so that a destination can be specified on the
    // logout link, e.g., caslogout?destination=http://foo.bar.com/foobar. We do
    // not allow absolute URLs to be passed via $_GET, as this can be an attack
    // vector.
    $destination = $_GET['destination'];
  }
  else {
    $destination = variable_get('cas_logout_destination', '');
  }

  //Make it an absolute url.  This will also convert <front> to the front page.
  if ($destination) {
    $destination_url = url($destination, array(
      'absolute' => TRUE,
    ));
    $options = array(
      'service' => $destination_url,
      'url' => $destination_url,
    );
  }
  else {
    $options = array();
  }

  // Mimic user_logout().
  if ($invoke_hook) {
    watchdog('user', 'Session closed for %name.', array(
      '%name' => format_username($user),
    ));
    module_invoke_all('user_logout', $user);
  }

  // phpCAS automatically calls session_destroy().
  phpCAS::logout($options);
}