You are here

public function Cookie::applies in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/src/Authentication/Provider/Cookie.php \Drupal\user\Authentication\Provider\Cookie::applies()
  2. 10 core/modules/user/src/Authentication/Provider/Cookie.php \Drupal\user\Authentication\Provider\Cookie::applies()

Checks whether suitable authentication credentials are on the request.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

bool TRUE if authentication credentials suitable for this provider are on the request, FALSE otherwise.

Overrides AuthenticationProviderInterface::applies

File

core/modules/user/src/Authentication/Provider/Cookie.php, line 71

Class

Cookie
Cookie based authentication provider.

Namespace

Drupal\user\Authentication\Provider

Code

public function applies(Request $request) {
  $applies = $request
    ->hasSession() && $this->sessionConfiguration
    ->hasSession($request);
  if (!$applies && $request->query
    ->has('check_logged_in')) {
    $domain = ltrim(ini_get('session.cookie_domain'), '.') ?: $request
      ->getHttpHost();
    $this->messenger
      ->addMessage($this
      ->t('To log in to this site, your browser must accept cookies from the domain %domain.', [
      '%domain' => $domain,
    ]), 'error');
  }
  return $applies;
}