/** * Updates the user last action * * @param PostResponseEvent $event */ public function onRequestTermination(PostResponseEvent $event) { $this->userFetcher->setThrowOnTokenError(false); if (null === ($user = $this->userFetcher->resolve())) { return; } $requestTime = $event->getRequest()->server->get('REQUEST_TIME'); $dateTime = new \DateTime(); $dateTime->setTimestamp($requestTime); $user->updateLastAction($dateTime); $this->userRepository->modify($user); }
/** * Checks if after authentication the locale cookie is invalid or if the "fixCookie" flag is true. * If the default locale is "en" and the user locale is "de", after authentication the cookie * will be changed * * @param FilterResponseEvent $event */ public function checkLocaleAfterAuthentication(FilterResponseEvent $event) { $user = $this->userFetcher->resolve(); if (null === $user && !$this->shouldFixCookie() || $event->getRequest()->attributes->get('_route') !== 'sen_user.request_api_key') { return; } $locale = $event->getRequest()->cookies->get('locale'); if ($user->getSimpleProfile()->getLocale() === $locale) { return; } $cookie = new Cookie('locale', $user->getSimpleProfile()->getLocale(), time() + 10 * 365 * 24 * 60 * 60); $response = $event->getResponse(); $response->headers->setCookie($cookie); }