You are here

public function Cookie::addCheckToUrl in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/user/src/Authentication/Provider/Cookie.php \Drupal\user\Authentication\Provider\Cookie::addCheckToUrl()

Adds a query parameter to check successful log in redirect URL.

Parameters

\Symfony\Component\HttpKernel\Event\ResponseEvent $event: The Event to process.

File

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

Class

Cookie
Cookie based authentication provider.

Namespace

Drupal\user\Authentication\Provider

Code

public function addCheckToUrl(ResponseEvent $event) {
  $response = $event
    ->getResponse();
  if ($response instanceof RedirectResponse && $event
    ->getRequest()
    ->hasSession()) {
    if ($event
      ->getRequest()
      ->getSession()
      ->has('check_logged_in')) {
      $event
        ->getRequest()
        ->getSession()
        ->remove('check_logged_in');
      $url = $response
        ->getTargetUrl();
      $options = UrlHelper::parse($url);
      $options['query']['check_logged_in'] = '1';
      $url = $options['path'] . '?' . UrlHelper::buildQuery($options['query']);
      if (!empty($options['#fragment'])) {
        $url .= '#' . $options['#fragment'];
      }

      // In the case of trusted redirect, we have to update the list of
      // trusted URLs because here we've just modified its target URL
      // which is in the list.
      if ($response instanceof TrustedRedirectResponse) {
        $response
          ->setTrustedTargetUrl($url);
      }
      $response
        ->setTargetUrl($url);
    }
  }
}