当前位置: 首页>>代码示例>>PHP>>正文


PHP SessionInterface::getId方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\SessionInterface::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionInterface::getId方法的具体用法?PHP SessionInterface::getId怎么用?PHP SessionInterface::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Session\SessionInterface的用法示例。


在下文中一共展示了SessionInterface::getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loginToDrupal

 /**
  * Attempts to log the authenticated CAS user into Drupal.
  *
  * This method should be used to login a user after they have successfully
  * authenticated with the CAS server.
  *
  * @param CasPropertyBag $property_bag
  *   CasPropertyBag containing username and attributes from CAS.
  * @param string $ticket
  *   The service ticket.
  *
  * @throws CasLoginException
  *   Thrown if there was a problem logging in the user.
  */
 public function loginToDrupal(CasPropertyBag $property_bag, $ticket)
 {
     // Dispatch an event that allows modules to change user data we received
     // from CAS before attempting to use it to load a Drupal user.
     // Auto-registration can also be disabled for this user if their account
     // does not exist.
     $user_load_event = new CasUserLoadEvent($property_bag);
     $this->eventDispatcher->dispatch(CasHelper::EVENT_USER_LOAD, $user_load_event);
     $account = $this->userLoadByName($property_bag->getUsername());
     if (!$account) {
         $config = $this->settings->get('cas.settings');
         if ($config->get('user_accounts.auto_register') === TRUE) {
             if ($user_load_event->allowAutoRegister) {
                 $account = $this->registerUser($property_bag->getUsername(), $config->get('user_accounts.auto_assigned_roles'));
             } else {
                 throw new CasLoginException("Cannot register user, an event listener denied access.");
             }
         } else {
             throw new CasLoginException("Cannot login, local Drupal user account does not exist.");
         }
     }
     // Dispatch an event that allows modules to prevent this user from logging
     // in and/or alter the user entity before we save it.
     $pre_auth_event = new CasPreAuthEvent($account, $property_bag);
     $this->eventDispatcher->dispatch(CasHelper::EVENT_PRE_AUTH, $pre_auth_event);
     // Save user entity since event listeners may have altered it.
     $account->save();
     if (!$pre_auth_event->allowLogin) {
         throw new CasLoginException("Cannot login, an event listener denied access.");
     }
     $this->userLoginFinalize($account);
     $this->storeLoginSessionData($this->session->getId(), $ticket);
 }
开发者ID:pulibrary,项目名称:recap,代码行数:47,代码来源:CasLogin.php

示例2:

 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();
 }
开发者ID:loic425,项目名称:Sylius,代码行数:9,代码来源:SecurityServiceSpec.php

示例3: logInUser

 /**
  * @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());
 }
开发者ID:Mozan,项目名称:Sylius,代码行数:10,代码来源:SecurityService.php

示例4: hasAuthenticatedBackendUser

 /**
  * Checks if there is an authenticated back end user.
  *
  * @param Request $request
  *
  * @return bool
  */
 private function hasAuthenticatedBackendUser(Request $request)
 {
     if (!$request->cookies->has('BE_USER_AUTH')) {
         return false;
     }
     $sessionHash = sha1(sprintf('%s%sBE_USER_AUTH', $this->session->getId(), $this->disableIpCheck ? '' : $request->getClientIp()));
     return $request->cookies->get('BE_USER_AUTH') === $sessionHash;
 }
开发者ID:contao,项目名称:core-bundle,代码行数:15,代码来源:BypassMaintenanceListener.php

示例5: generateCookie

 protected function generateCookie()
 {
     $lifetime = $this->options->getInt('cookie_lifetime');
     if ($lifetime !== 0) {
         $lifetime += time();
     }
     return new Cookie($this->session->getName(), $this->session->getId(), $lifetime, $this->options['cookie_path'], $this->options['cookie_domain'] ?: null, $this->options->getBoolean('cookie_secure'), $this->options->getBoolean('cookie_httponly'));
 }
开发者ID:nbehier,项目名称:bolt,代码行数:8,代码来源:SessionListener.php

示例6: writeSessionTo

 /**
  * Write the session cookie to the response.
  *
  * @param \Symfony\Component\HttpFoundation\Response $response
  * @return void
  */
 protected function writeSessionTo(Response $response)
 {
     // TODO: Take these values from config
     $lifetime = Carbon::now()->addMinutes(120);
     $path = '/';
     $domain = null;
     $secure = false;
     $response->headers->setCookie(new Cookie($this->session->getName(), $this->session->getId(), $lifetime, $path, $domain, $secure));
 }
开发者ID:fluxbb,项目名称:core,代码行数:15,代码来源:SessionKernel.php

示例7: logIn

 /**
  * {@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());
 }
开发者ID:Mangetsu,项目名称:Sylius,代码行数:14,代码来源:SecurityService.php

示例8: getConfig

 public function getConfig()
 {
     $sessionInfo = ['isStarted' => false];
     if ($this->session->isStarted()) {
         $sessionInfo['isStarted'] = true;
         $sessionInfo['name'] = $this->session->getName();
         $sessionInfo['identifier'] = $this->session->getId();
         $sessionInfo['csrfToken'] = $this->csrfTokenManager->getToken($this->csrfTokenIntention)->getValue();
         $sessionInfo['href'] = $this->generateUrl('ezpublish_rest_deleteSession', ['sessionId' => $this->session->getId()]);
     }
     return $sessionInfo;
 }
开发者ID:yed30,项目名称:PlatformUIBundle,代码行数:12,代码来源:SessionInfo.php

示例9: processRecord

 /**
  * Adds session id to log record.
  *
  * @param array $record
  *
  * @return array
  */
 public function processRecord(array $record)
 {
     if (null === $this->token) {
         try {
             $this->token = substr($this->session->getId(), 0, 8);
         } catch (\RuntimeException $e) {
             $this->token = '????????';
         }
         $this->token = $this->hash($this->token);
     }
     $record['extra']['token'] = $this->token;
     return $record;
 }
开发者ID:martiis,项目名称:monolog-session-processor,代码行数:20,代码来源:SessionRequestProcessor.php

示例10: getSessionId

 /**
  * @return string
  */
 public function getSessionId()
 {
     try {
         if ($this->startSession && !$this->session->isStarted()) {
             $this->session->start();
         }
         if ($this->session->isStarted()) {
             return $this->session->getId();
         }
     } catch (\RuntimeException $e) {
     }
     return self::SESSION_ID_UNKNOWN;
 }
开发者ID:Hexanet,项目名称:MonologExtraBundle,代码行数:16,代码来源:SymfonySessionIdProvider.php

示例11: setToken

 /**
  * @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());
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:10,代码来源:SecurityService.php

示例12: getToken

 /**
  * Generate Hash-Token from string
  *
  * @param string $value
  * @param string $secret
  * @return string
  */
 public function getToken($value, $secret = null)
 {
     if ($secret === null) {
         $secret = $this->secret;
     }
     // Create real key for value
     $sessionId = $this->session->getId();
     $realHash = sha1($value . $sessionId . $secret);
     return $realHash;
 }
开发者ID:odan,项目名称:molengo,代码行数:17,代码来源:UserSession.php

示例13: makeCookie

 protected function makeCookie(Request $request)
 {
     // merge native PHP session cookie params with custom ones.
     $params = array_replace(session_get_cookie_params(), $this->cookies);
     // if the cookie lifetime is not 0 (closes when browser window closes),
     // add the request time and the lifetime to get the expiration time of
     // the cookie.
     if ($params['lifetime'] !== 0) {
         $params['lifetime'] = $request->server->get('REQUEST_TIME') + $params['lifetime'];
     }
     return new Cookie($this->session->getName(), $this->session->getId(), $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
 }
开发者ID:autarky,项目名称:framework,代码行数:12,代码来源:SessionMiddleware.php

示例14: generate

 /**
  * {@inheritDoc}
  */
 public function generate($key)
 {
     if (!is_string($key)) {
         throw new InvalidTypeException($key, 'string');
     }
     if (empty($key)) {
         throw new \InvalidArgumentException('Argument must not be empty.');
     }
     $token = $this->tokenStorage->getToken();
     if ($token instanceof TokenInterface && !$token instanceof AnonymousToken) {
         $username = $token->getUsername();
         if (!empty($username)) {
             return sprintf('user_%s_%s', $username, $key);
         }
     }
     // fallback to session id
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return sprintf('session_%s_%s', $this->session->getId(), $key);
 }
开发者ID:alinnflorinn,项目名称:CraueFormFlowBundle,代码行数:24,代码来源:UserSessionStorageKeyGenerator.php

示例15:

 function it_logs_user_in(UserRepositoryInterface $userRepository, SessionInterface $session, CookieSetterInterface $cookieSetter, UserInterface $user)
 {
     $userRepository->findOneBy(['username' => 'sylius@example.com'])->willReturn($user);
     $user->getRoles()->willReturn(['ROLE_USER']);
     $user->getPassword()->willReturn('xyz');
     $user->serialize()->willReturn('serialized_user');
     $session->set('_security_context_name', Argument::any())->shouldBeCalled();
     $session->save()->shouldBeCalled();
     $session->getName()->willReturn('MOCKEDSID');
     $session->getId()->willReturn('xyzc123');
     $cookieSetter->setCookie('MOCKEDSID', 'xyzc123')->shouldBeCalled();
     $this->logIn('sylius@example.com');
 }
开发者ID:TeamNovatek,项目名称:Sylius,代码行数:13,代码来源:SecurityServiceSpec.php


注:本文中的Symfony\Component\HttpFoundation\Session\SessionInterface::getId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。