コード例 #1
0
ファイル: SessionTokenStorage.php プロジェクト: ayoah/symfony
 /**
  * {@inheritdoc}
  */
 public function hasToken($tokenId)
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return $this->session->has($this->namespace . '/' . $tokenId);
 }
コード例 #2
0
ファイル: SessionStorage.php プロジェクト: Avazanga1/Sylius
 /**
  * {@inheritdoc}
  */
 public function hasData($key)
 {
     if (!$this->session->isStarted()) {
         return false;
     }
     return $this->session->has($key);
 }
コード例 #3
0
 /**
  * @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;
 }
コード例 #4
0
ファイル: QuoteSession.php プロジェクト: spryker/Cart
 /**
  * @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);
 }
コード例 #5
0
 /**
  * @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));
 }
コード例 #6
0
 /**
  * @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();
 }
コード例 #7
0
 /**
  * @return bool
  */
 public function hasEditId()
 {
     if (!$this->session->has('scribe.digitalhub.editId')) {
         return false;
     }
     return true;
 }
コード例 #8
0
 /**
  * {@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;
 }
コード例 #9
0
ファイル: AgileController.php プロジェクト: spiasecki/ubirimi
 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());
 }
コード例 #10
0
 /**
  * {@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;
 }
コード例 #11
0
 /**
  * @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;
 }
コード例 #12
0
 /**
  * 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));
 }
コード例 #13
0
 /**
  * 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;
 }
コード例 #14
0
 /**
  * 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;
 }
コード例 #15
0
ファイル: StartSession.php プロジェクト: Luceos/core
 private function withCsrfTokenHeader(Response $response, SessionInterface $session)
 {
     if ($session->has('csrf_token')) {
         $response = $response->withHeader('X-CSRF-Token', $session->get('csrf_token'));
     }
     return $response;
 }
コード例 #16
0
ファイル: Controller.php プロジェクト: deefour/aide
 /**
  * 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');
 }
コード例 #17
0
 /**
  * @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');
         }
     }
 }
コード例 #18
0
 /**
  * @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;
 }
コード例 #19
0
ファイル: WhoopsListener.php プロジェクト: robbert-vdh/bolt
 /**
  * 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));
 }
コード例 #20
0
 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');
 }
コード例 #21
0
 /**
  * {@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;
 }
コード例 #22
0
ファイル: ExceptionListener.php プロジェクト: atiarda/bolt
 /**
  * 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;
 }
コード例 #23
0
 /**
  * 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);
 }
コード例 #24
0
 /**
  * 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]);
 }
コード例 #25
0
 public function check(SessionInterface $session = null)
 {
     if ($session === null) {
         return false;
     }
     if ($session->has($this->sessionKey)) {
         return true;
     }
     return false;
 }
コード例 #26
0
ファイル: Builder.php プロジェクト: vicens/captcha
 /**
  * 仅验证验证码正确性
  * @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);
 }
コード例 #27
0
 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');
 }
コード例 #28
0
ファイル: Session.php プロジェクト: Mozan/core-bundle
 /**
  * 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;
 }
コード例 #29
0
ファイル: Session.php プロジェクト: contao/core-bundle
 /**
  * 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;
 }
コード例 #30
0
 /**
  * @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;
 }