本文整理汇总了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);
}
示例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();
}
示例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());
}
示例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;
}
示例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'));
}
示例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));
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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']);
}
示例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);
}
示例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');
}