You are here

public function UserAuthenticationController::loginStatus in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/src/Controller/UserAuthenticationController.php \Drupal\user\Controller\UserAuthenticationController::loginStatus()

Checks whether a user is logged in or not.

Return value

\Symfony\Component\HttpFoundation\Response The response.

1 string reference to 'UserAuthenticationController::loginStatus'
user.routing.yml in core/modules/user/user.routing.yml
core/modules/user/user.routing.yml

File

core/modules/user/src/Controller/UserAuthenticationController.php, line 319

Class

UserAuthenticationController
Provides controllers for login, login status and logout via HTTP requests.

Namespace

Drupal\user\Controller

Code

public function loginStatus() {
  if ($this
    ->currentUser()
    ->isAuthenticated()) {
    $response = new Response(self::LOGGED_IN);
  }
  else {
    $response = new Response(self::LOGGED_OUT);
  }
  $response->headers
    ->set('Content-Type', 'text/plain');
  return $response;
}