/** * {@inheritdoc} */ public function hasToken($tokenId) { if (!$this->session->isStarted()) { $this->session->start(); } return $this->session->has($this->namespace . '/' . $tokenId); }
/** * {@inheritdoc} */ public function hasData($key) { if (!$this->session->isStarted()) { return false; } return $this->session->has($key); }
/** * @return \PHPSC\Conference\Domain\Entity\User */ public function getLoggedUser() { if (!$this->isLogged() && $this->session->has('loggedUser')) { $this->loggedUser = $this->userManager->getById($this->session->get('loggedUser')); } return $this->loggedUser; }
/** * @return int */ public function getItemCount() { if (!$this->session->has(self::QUOTE_SESSION_ITEM_COUNT_IDENTIFIER)) { return 0; } return $this->session->get(self::QUOTE_SESSION_ITEM_COUNT_IDENTIFIER); }
/** * @param Task $task * @return bool true if task is skipped */ public function checkTaskSkipped(Task $task) { if (!$this->session) { return false; } return $this->session->has($this->getSessionKey($task)); }
/** * @return string */ public function getHost() { if ($this->session->isStarted() && $this->session->has(self::OVERRIDE_HOST)) { return $this->session->get(self::OVERRIDE_HOST); } return parent::getHost(); }
/** * @return bool */ public function hasEditId() { if (!$this->session->has('scribe.digitalhub.editId')) { return false; } return true; }
/** * {@inheritdoc} */ protected function getId($create = TRUE) { if ($this->currentUser->isAuthenticated()) { return $this->currentUser->id(); } elseif (!$this->session->has('uc_cart_id') && $create) { $this->session->set('uc_cart_id', md5(uniqid(rand(), TRUE))); } return $this->session->has('uc_cart_id') ? $this->session->get('uc_cart_id') : FALSE; }
public function indexAction(Request $request, SessionInterface $session) { $last5Board = $this->getRepository(Board::class)->getLast5BoardsByClientId($session->get('client/id')); $recentBoard = null; if ($session->has('last_selected_board_id')) { $recentBoard = $this->getRepository(Board::class)->getById($session->has('last_selected_board_id')); } $clientAdministratorFlag = $session->get('user/client_administrator_flag'); return $this->render(__DIR__ . '/../../Resources/views/menu/Agile.php', get_defined_vars()); }
/** * {@inheritdoc} */ public function getCart() { if (!$this->session->has($this->sessionKeyName)) { throw new CartNotFoundException('Sylius was not able to find the cart in session'); } $cart = $this->cartRepository->findCartById($this->session->get($this->sessionKeyName)); if (null === $cart) { $this->session->remove($this->sessionKeyName); throw new CartNotFoundException('Sylius was not able to find the cart in session'); } return $cart; }
/** * @return Comunidad|mixed|null|object * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException */ public function get() { if ($this->comunidad instanceof Comunidad) { return $this->comunidad; } if ($this->session->has('comunidad')) { $comunidad = $this->session->get('comunidad'); $this->comunidad = $this->em->merge($comunidad); return $this->comunidad; } return null; }
/** * Handle errors thrown in the application. * * @param GetResponseForExceptionEvent $event */ public function onKernelException(GetResponseForExceptionEvent $event) { $hasUser = $this->session->isStarted() && $this->session->has('authentication'); if (!$hasUser && !$this->showWhileLoggedOff) { return; } $exception = $event->getException(); ob_start(); $this->whoops->handleException($exception); $response = ob_get_clean(); $code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR; $event->setResponse(new Response($response, $code)); }
/** * Return if the translations are saved in the session * * @param string $key * @return bool */ public function hasValid($key = self::DEFAULT_KEY) { if (!$this->session->has($key)) { return false; } $rawTranslations = $this->session->get($key); if (!is_array($rawTranslations)) { return false; } if (!isset($rawTranslations['bundles']) || !isset($rawTranslations['domains']) || !isset($rawTranslations['locales']) || !isset($rawTranslations['bundles']) || !isset($rawTranslations['messages'])) { return false; } return true; }
/** * Retrieve the CAPTCHA code * *@param $key * * @return mixed|null */ protected function getExpectedCode($key) { $arrayZendSession = new SessionArrayStorage(); if ($this->session->has($key)) { $sessionKey = $this->session->get($key); $this->session->remove($key); $captchaSession = $arrayZendSession->offsetGet($sessionKey); $arrayZendSession->offsetUnset($sessionKey); if ($captchaSession instanceof ArrayObject) { $word = $captchaSession->offsetGet('word'); $captchaSession->offsetUnset('word'); return $word; } } return null; }
private function withCsrfTokenHeader(Response $response, SessionInterface $session) { if ($session->has('csrf_token')) { $response = $response->withHeader('X-CSRF-Token', $session->get('csrf_token')); } return $response; }
/** * Boolean check whether the user is logged into the app or not * * @protected * @return boolean */ protected function authenticated() { if (!$this->session instanceof SessionInterface) { throw new \Exception('The `$session` property must be set on the `' . get_class($this) . '` to an instance of `\\Symfony\\Component\\HttpFoundation\\Session\\SessionInterface` in order to call the `authenticated()` shortcut.'); } return $this->session->has('user_id'); }
/** * @param FormEvent $event */ public function validate(FormEvent $event) { $form = $event->getForm(); $data = $form->getData(); if (!is_array($data) || !isset($data['code']) || !isset($data['key'])) { $form->addError(new FormError($this->translator->trans($this->invalidMessage, array(), 'validators'))); return; } $this->key = $data['key']; $code = $data['code']; $expectedCode = $this->getExpectedCode(); if ($this->humanity > 0) { $humanity = $this->getHumanity(); if ($humanity > 0) { $this->updateHumanity($humanity - 1); return; } } if (!($code && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) { $form->addError(new FormError($this->translator->trans($this->invalidMessage, array(), 'validators'))); } else { if ($this->humanity > 0) { $this->updateHumanity($this->humanity); } } if (!$this->container->get('sf.form.listener')->isXhrRequest()) { $this->session->remove($this->key); if ($this->session->has($this->key . '_fingerprint')) { $this->session->remove($this->key . '_fingerprint'); } } }
/** * @return bool */ public function getShowTierPrices() { $showTierPrices = parent::getShowTierPrices(); if ((!$this->request || $this->request && !$this->request->get(self::TIER_PRICES_KEY)) && $this->session->has(self::TIER_PRICES_KEY)) { $showTierPrices = $this->session->get(self::TIER_PRICES_KEY); } if (is_string($showTierPrices)) { $showTierPrices = filter_var($showTierPrices, FILTER_VALIDATE_BOOLEAN); } else { $showTierPrices = (bool) $showTierPrices; } if ($this->request && $this->request->get(self::SAVE_STATE_KEY)) { $this->session->set(self::TIER_PRICES_KEY, $showTierPrices); } return $showTierPrices; }
/** * Handle errors thrown in the application. * * Note: * - We don't want to show Whoops! screens for requests that trigger a 404. * - Our priority is set just above Symfony's, as we are giving up and * displaying the error to the user, so that should be a low priority * compared to error handlers that do something else. * * @param GetResponseForExceptionEvent $event */ public function onKernelException(GetResponseForExceptionEvent $event) { // We (generally) do not want to show Whoops! screens when the user isn't logged on. $hasUser = $this->session->isStarted() && $this->session->has('authentication'); if (!$hasUser && !$this->showWhileLoggedOff) { return; } // Register Whoops as an error handler $this->whoops->register(); $exception = $event->getException(); ob_start(); $this->whoops->handleException($exception); $response = ob_get_clean(); $code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR; $event->setResponse(new Response($response, $code)); }
function it_throws_cart_not_found_exception_and_removes_id_from_session_when_cart_is_not_found(SessionInterface $session, OrderRepositoryInterface $orderRepository) { $session->has('session_key_name')->willReturn(true); $session->get('session_key_name')->willReturn(12345); $orderRepository->findCartById(12345)->willReturn(null); $session->remove('session_key_name')->shouldBeCalled(); $this->shouldThrow(CartNotFoundException::class)->during('getCart'); }
/** * {@inheritdoc} */ public function getCart() { try { $channel = $this->channelContext->getChannel(); } catch (ChannelNotFoundException $exception) { throw new CartNotFoundException($exception); } if (!$this->session->has(sprintf('%s.%s', $this->sessionKeyName, $channel->getCode()))) { throw new CartNotFoundException('Sylius was not able to find the cart in session'); } $cart = $this->orderRepository->findCartByIdAndChannel($this->session->get(sprintf('%s.%s', $this->sessionKeyName, $channel->getCode())), $channel); if (null === $cart) { $this->session->remove(sprintf('%s.%s', $this->sessionKeyName, $channel->getCode())); throw new CartNotFoundException('Sylius was not able to find the cart in session'); } return $cart; }
/** * Get the exception trace that is safe to display publicly * * @param Exception $exception * * @return array */ protected function getSafeTrace(Exception $exception) { if (!$this->isDebug && !($this->session->isStarted() && $this->session->has('authentication'))) { return []; } $trace = $exception->getTrace(); foreach ($trace as $key => $value) { if (!empty($value['file']) && strpos($value['file'], '/vendor/') > 0) { unset($trace[$key]['args']); } // Don't display the full path. if (isset($trace[$key]['file'])) { $trace[$key]['file'] = str_replace($this->rootPath, '[root]/', $trace[$key]['file']); } } return $trace; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('auth/login'); } } elseif (!$this->session->has('github.user_is_org_owner')) { // Fetch user_org if not cached $this->session->set('github.user_is_org_owner', $this->isOrgOwner()); } if (!$this->session->get('github.user_is_org_owner')) { // Unauthorized return redirect()->guest('profile')->withErrors(_('You are not authorized to get to this part of the site.')); } return $next($request); }
/** * Dummy success page * @return Response */ public function successAction() { if (!$this->session->has('cardinity_payment')) { return $this->errorResponse('Session expired.'); } $payment = new Payment\Payment(); $payment->unserialize($this->session->get('cardinity_payment')); $this->session->remove('cardinity_payment'); return $this->templating->renderResponse('CardinityClientBundle:Payment:success.html.twig', ['payment' => $payment]); }
public function check(SessionInterface $session = null) { if ($session === null) { return false; } if ($session->has($this->sessionKey)) { return true; } return false; }
/** * 仅验证验证码正确性 * @param $input * @return bool */ protected function test($input) { if (!($this->store->has($this->getFullName()) && $input)) { return false; } //从Session中取回code $code = $this->store->get($this->getFullName()); //返回验证结果 return password_verify(strtolower($input), $code); }
function it_throws_cart_not_found_exception_and_removes_id_from_session_when_cart_was_not_found(SessionInterface $session, OrderRepositoryInterface $orderRepository, ChannelContextInterface $channelContext, ChannelInterface $channel) { $channelContext->getChannel()->willReturn($channel); $channel->getCode()->willReturn('Poland'); $session->has('session_key_name.Poland')->willReturn(true); $session->get('session_key_name.Poland')->willReturn(12345); $orderRepository->findCartByChannel(12345, $channel)->willReturn(null); $session->remove('session_key_name.Poland')->shouldBeCalled(); $this->shouldThrow(CartNotFoundException::class)->during('getCart'); }
/** * Return the session data as array * * @return array The session data */ public function getData() { @trigger_error('Using Session::getData() has been deprecated and will no longer work in Contao 5.0. Use the Symfony session via the container instead.', E_USER_DEPRECATED); $data = $this->sessionBag->all(); unset($data['referer']); // Map the referer (see #281) if ($this->session->has('referer')) { $data['referer'] = $this->session->get('referer'); } return $data; }
/** * Return the session data as array * * @return array The session data */ public function getData() { $data = $this->sessionBag->all(); // Map the referer (see #281) foreach ($this->mappedKeys as $strKey) { unset($data[$strKey]); if ($this->session->has($strKey)) { $data[$strKey] = $this->session->get($strKey); } } return $data; }
/** * @param $service * @param $userInfo * @return mixed * @throws MissingEmailException */ private function checkEmail($service, $userInfo) { if (!$userInfo['email'] || $this->session->has("{$service}.email")) { if (!$this->session->get("{$service}.email")) { $this->session->set("{$service}.userinfo", $userInfo); throw new MissingEmailException($service); } $userInfo['email'] = $this->session->get("{$service}.email"); $this->session->remove("{$service}.email"); $this->session->remove("{$service}.userinfo"); } return $userInfo; }