public function TokenHandler::loadTokenOnRequestEvent in Persistent Login 8
Load a token on this request, if a persistent cookie is provided.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The request event.
File
- src/
EventSubscriber/ TokenHandler.php, line 107
Class
- TokenHandler
- Class TokenHandler.
Namespace
Drupal\persistent_login\EventSubscriberCode
public function loadTokenOnRequestEvent(GetResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
$request = $event
->getRequest();
if ($this->cookieHelper
->hasCookie($request)) {
$this->token = $this
->getTokenFromCookie($request);
// Only validate the token if a user session has not been started.
if (!$this->sessionConfiguration
->hasSession($request)) {
$this->token = $this->tokenManager
->validateToken($this->token);
if ($this->token
->getStatus() === PersistentToken::STATUS_VALID) {
try {
// TODO make sure we are starting the user session properly.
/** @var \Drupal\User\UserInterface $user */
$user = $this->entityTypeManager
->getStorage('user')
->load($this->token
->getUid());
user_login_finalize($user);
} catch (PluginException $e) {
}
}
}
}
}