function UserAuthenticationController::loginStatus
Same name and namespace in other branches
- 11.x core/modules/user/src/Controller/UserAuthenticationController.php \Drupal\user\Controller\UserAuthenticationController::loginStatus()
- 10 core/modules/user/src/Controller/UserAuthenticationController.php \Drupal\user\Controller\UserAuthenticationController::loginStatus()
- 9 core/modules/user/src/Controller/UserAuthenticationController.php \Drupal\user\Controller\UserAuthenticationController::loginStatus()
- 8.9.x core/modules/user/src/Controller/UserAuthenticationController.php \Drupal\user\Controller\UserAuthenticationController::loginStatus()
Checks whether a user is logged in or not.
Attributes
#[Route(path: '/user/login_status', name: 'user.login_status.http', methods: [
'GET',
], requirements: [
'_access' => 'TRUE',
'_format' => 'json',
])]
Return value
\Symfony\Component\HttpFoundation\Response The response.
File
-
core/
modules/ user/ src/ Controller/ UserAuthenticationController.php, line 349
Class
- UserAuthenticationController
- Provides controllers for login, login status and logout via HTTP requests.
Namespace
Drupal\user\ControllerCode
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.