function UserAuthenticationController::loginStatus

Same name in other branches
  1. 9 core/modules/user/src/Controller/UserAuthenticationController.php \Drupal\user\Controller\UserAuthenticationController::loginStatus()
  2. 8.9.x core/modules/user/src/Controller/UserAuthenticationController.php \Drupal\user\Controller\UserAuthenticationController::loginStatus()
  3. 10 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 353

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.