You are here

function _user_resource_logout in Services 7.3

Same name and namespace in other branches
  1. 6.3 resources/user_resource.inc \_user_resource_logout()

Logout the current user.

1 string reference to '_user_resource_logout'
_user_resource_definition in resources/user_resource.inc

File

resources/user_resource.inc, line 659

Code

function _user_resource_logout() {
  global $user;
  if (!$user->uid) {

    // User is not logged in
    return services_error(t('User is not logged in.'), 406);
  }
  watchdog('user', 'Session closed for %name.', array(
    '%name' => $user->name,
  ));
  $original_session_state = drupal_save_session();
  drupal_save_session(TRUE);

  // Destroy the current session.
  module_invoke_all('user_logout', $user);
  session_destroy();

  // Load the anonymous user.
  $user = drupal_anonymous_user();
  drupal_save_session($original_session_state);
  return TRUE;
}