function it_logs_user_out(SessionInterface $session, CookieSetterInterface $cookieSetter) { $session->set('_security_shop', null)->shouldBeCalled(); $session->save()->shouldBeCalled(); $session->getName()->willReturn('MOCKEDSID'); $session->getId()->willReturn('xyzc123'); $cookieSetter->setCookie('MOCKEDSID', 'xyzc123')->shouldBeCalled(); $this->logOut(); }
/** * @param UserInterface $user */ private function logInUser(UserInterface $user) { $token = new UsernamePasswordToken($user, $user->getPassword(), 'randomstringbutnotnull', $user->getRoles()); $this->session->set($this->sessionTokenVariable, serialize($token)); $this->session->save(); $this->cookieSetter->setCookie($this->session->getName(), $this->session->getId()); }
/** * Save the translations in the session * * @param Translations $translations * @param string $key * @return bool */ public function save(Translations $translations, $key = self::DEFAULT_KEY) { $rawTranslations = $translations->getRawData(); $this->session->set($key, $rawTranslations); $this->session->save(); return true; }
/** * Add the session cookie to the response if it is started. * * @param FilterResponseEvent $event */ public function onResponse(FilterResponseEvent $event) { if (!$event->isMasterRequest() || !$this->session->isStarted()) { return; } $this->session->save(); $cookie = $this->generateCookie(); $event->getResponse()->headers->setCookie($cookie); }
/** * @inheritDoc */ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { $this->startSession($request); $request->setSession($this->session); $response = $this->wrapped->handle($request, $type, $catch); $this->session->save(); $this->writeSessionTo($response); return $response; }
/** * {@inheritdoc} */ public function logIn($email, $providerKey, Session $minkSession) { $user = $this->userRepository->findOneBy(['username' => $email]); if (null === $user) { throw new \InvalidArgumentException(sprintf('There is no user with email %s', $email)); } $token = new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles()); $this->session->set('_security_user', serialize($token)); $this->session->save(); $minkSession->setCookie($this->session->getName(), $this->session->getId()); }
/** * {@inheritdoc} */ public function sendContent($content, array $attachments) { // First, gather the BigPipe placeholders that must be replaced. $placeholders = isset($attachments['big_pipe_placeholders']) ? $attachments['big_pipe_placeholders'] : []; $nojs_placeholders = isset($attachments['big_pipe_nojs_placeholders']) ? $attachments['big_pipe_nojs_placeholders'] : []; // BigPipe sends responses using "Transfer-Encoding: chunked". To avoid // sending already-sent assets, it is necessary to track cumulative assets // from all previously rendered/sent chunks. // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41 $cumulative_assets = AttachedAssets::createFromRenderArray(['#attached' => $attachments]); $cumulative_assets->setAlreadyLoadedLibraries($attachments['library']); // The content in the placeholders may depend on the session, and by the // time the response is sent (see index.php), the session is already closed. // Reopen it for the duration that we are rendering placeholders. $this->session->start(); // Find the closing </body> tag and get the strings before and after. But be // careful to use the latest occurrence of the string "</body>", to ensure // that strings in inline JavaScript or CDATA sections aren't used instead. $parts = explode('</body>', $content); $post_body = array_pop($parts); $pre_body = implode('', $parts); $this->sendPreBody($pre_body, $nojs_placeholders, $cumulative_assets); $this->sendPlaceholders($placeholders, $this->getPlaceholderOrder($pre_body, $placeholders), $cumulative_assets); $this->sendPostBody($post_body); // Close the session again. $this->session->save(); return $this; }
/** * @param TokenInterface $token */ private function setToken(TokenInterface $token) { $serializedToken = serialize($token); $this->session->set($this->sessionTokenVariable, $serializedToken); $this->session->save(); $this->cookieSetter->setCookie($this->session->getName(), $this->session->getId()); }
protected function closeSession(Request $request, Response $response) { // save all session data $this->session->save(); // attach the session cookie $response->headers->setCookie($this->makeCookie($request)); }
function it_does_not_log_user_in_if_user_was_not_found(UserRepositoryInterface $userRepository, SessionInterface $session, CookieSetterInterface $cookieSetter) { $userRepository->findOneBy(['username' => '*****@*****.**'])->willReturn(null); $session->set(Argument::cetera())->shouldNotBeCalled(); $session->save()->shouldNotBeCalled(); $cookieSetter->setCookie(Argument::cetera())->shouldNotBeCalled(); $this->shouldThrow(new \InvalidArgumentException(sprintf('There is no user with email sylius@example.com')))->during('logIn', ['*****@*****.**']); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { if (null !== $options['crop_by_ratio'] && null !== $options['crop_by_size'] && true === (bool) $options['allow_crop']) { throw new \InvalidArgumentException('Multiple crop strategies at the same field are not allowed.'); } if (null !== $options['crop_by_size'] && (!is_array($options['crop_by_size']) || !isset($options['crop_by_size']['w']) || !isset($options['crop_by_size']['h']))) { throw new \InvalidArgumentException('crop_by_size requires array [w => [int], h => [int]].'); } $uniqueKey = md5(microtime() . rand()); $sessionData = array('handler' => $options['handler'], 'imagine_filter' => $options['imagine_filter'], 'options' => array('accept_file_type' => $options['accept_file_type'], 'allow_multiple' => $options['allow_multiple'], 'allow_crop' => $options['allow_crop'], 'crop_by_size' => $options['crop_by_size'], 'crop_by_ratio' => $options['crop_by_ratio']), 'handler_options' => array('save_path' => $options['save_path'], 'web_path' => $options['web_path'])); $this->session->set($uniqueKey, $sessionData); $this->session->save(); $view->vars['unique_key'] = $uniqueKey; $view->vars['imagine_filter'] = $options['imagine_filter']; $view->vars['allow_crop'] = $options['allow_crop']; $view->vars['crop_by_ratio'] = $options['crop_by_ratio']; $view->vars['crop_by_size'] = $options['crop_by_size']; }
/** * @param BaseUser $user * @param SessionInterface $session * @param $firewall * @throws UnsupportedDriverActionException */ public function login(BaseUser $user, SessionInterface $session, $firewall) { $driver = $this->getDriver(); if (!$driver instanceof BrowserKitDriver) { //Fall back to manual login if BrowserKitDriver is not used throw new UnsupportedDriverActionException("Not supported by the current driver", $driver); } $client = $driver->getClient(); $client->getCookieJar()->set(new Cookie(session_name(), true)); $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); $session->set('_security_' . $firewall, serialize($token)); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); $client->getCookieJar()->set($cookie); }
/** * {@inheritdoc} */ public function sendContent($content, array $attachments) { // First, gather the BigPipe placeholders that must be replaced. $placeholders = isset($attachments['big_pipe_placeholders']) ? $attachments['big_pipe_placeholders'] : []; $nojs_placeholders = isset($attachments['big_pipe_nojs_placeholders']) ? $attachments['big_pipe_nojs_placeholders'] : []; // BigPipe sends responses using "Transfer-Encoding: chunked". To avoid // sending already-sent assets, it is necessary to track cumulative assets // from all previously rendered/sent chunks. // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41 $cumulative_assets = AttachedAssets::createFromRenderArray(['#attached' => $attachments]); $cumulative_assets->setAlreadyLoadedLibraries(explode(',', $attachments['drupalSettings']['ajaxPageState']['libraries'])); // The content in the placeholders may depend on the session, and by the // time the response is sent (see index.php), the session is already closed. // Reopen it for the duration that we are rendering placeholders. $this->session->start(); list($pre_body, $post_body) = explode('</body>', $content, 2); $this->sendPreBody($pre_body, $nojs_placeholders, $cumulative_assets); $this->sendPlaceholders($placeholders, $this->getPlaceholderOrder($pre_body), $cumulative_assets); $this->sendPostBody($post_body); // Close the session again. $this->session->save(); return $this; }
public function testSave() { $this->session->start(); $this->session->save(); }
/** * @param string $token */ private function setSerializedToken($token) { $this->session->set($this->sessionTokenVariable, $token); $this->session->save(); }