You are here

public function UserSessionState::switchUserBack in RESTful 7.2

Switch the user to the authenticated user, and back.

This should be called only for an API call. It should not be used for calls via the menu system, as it might be a login request, so we avoid switching back to the anonymous user.

Overrides UserSessionStateInterface::switchUserBack

File

src/Authentication/UserSessionState.php, line 77
Contains \Drupal\restful\Authentication\UserSessionState.

Class

UserSessionState
Class UserSessionState.

Namespace

Drupal\restful\Authentication

Code

public function switchUserBack() {
  global $user;
  if (!$this->originalUser) {
    return;
  }
  $user = $this->originalUser;
  drupal_save_session($this->needsSaving);
  $this
    ->reset();
}