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


PHP WebRequest::getSessionData方法代码示例

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


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

示例1: testBeginAuthentication

 public function testBeginAuthentication()
 {
     $this->initializeManager();
     // Immutable session
     list($provider, $reset) = $this->getMockSessionProvider(false);
     $this->hook('UserLoggedIn', $this->never());
     $this->request->getSession()->setSecret('AuthManager::authnState', 'test');
     try {
         $this->manager->beginAuthentication([], 'http://localhost/');
         $this->fail('Expected exception not thrown');
     } catch (\LogicException $ex) {
         $this->assertSame('Authentication is not possible now', $ex->getMessage());
     }
     $this->unhook('UserLoggedIn');
     $this->assertNull($this->request->getSession()->getSecret('AuthManager::authnState'));
     \ScopedCallback::consume($reset);
     $this->initializeManager(true);
     // CreatedAccountAuthenticationRequest
     $user = \User::newFromName('UTSysop');
     $reqs = [new CreatedAccountAuthenticationRequest($user->getId(), $user->getName())];
     $this->hook('UserLoggedIn', $this->never());
     try {
         $this->manager->beginAuthentication($reqs, 'http://localhost/');
         $this->fail('Expected exception not thrown');
     } catch (\LogicException $ex) {
         $this->assertSame('CreatedAccountAuthenticationRequests are only valid on the same AuthManager ' . 'that created the account', $ex->getMessage());
     }
     $this->unhook('UserLoggedIn');
     $this->request->getSession()->clear();
     $this->request->getSession()->setSecret('AuthManager::authnState', 'test');
     $this->managerPriv->createdAccountAuthenticationRequests = [$reqs[0]];
     $this->hook('UserLoggedIn', $this->once())->with($this->callback(function ($u) use($user) {
         return $user->getId() === $u->getId() && $user->getName() === $u->getName();
     }));
     $this->hook('AuthManagerLoginAuthenticateAudit', $this->once());
     $this->logger->setCollect(true);
     $ret = $this->manager->beginAuthentication($reqs, 'http://localhost/');
     $this->logger->setCollect(false);
     $this->unhook('UserLoggedIn');
     $this->unhook('AuthManagerLoginAuthenticateAudit');
     $this->assertSame(AuthenticationResponse::PASS, $ret->status);
     $this->assertSame($user->getName(), $ret->username);
     $this->assertSame($user->getId(), $this->request->getSessionData('AuthManager:lastAuthId'));
     $this->assertEquals(time(), $this->request->getSessionData('AuthManager:lastAuthTimestamp'), 'timestamp ±1', 1);
     $this->assertNull($this->request->getSession()->getSecret('AuthManager::authnState'));
     $this->assertSame($user->getId(), $this->request->getSession()->getUser()->getId());
     $this->assertSame([[LogLevel::INFO, 'Logging in {user} after account creation']], $this->logger->getBuffer());
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:48,代码来源:AuthManagerTest.php

示例2: getEditTokenAtTimestamp

 /**
  * Internal implementation for self::getEditToken() and
  * self::matchEditToken().
  *
  * @param string|array $salt
  * @param WebRequest $request
  * @param string|int $timestamp
  * @return string
  */
 private function getEditTokenAtTimestamp($salt, $request, $timestamp)
 {
     if ($this->isAnon()) {
         return self::EDIT_TOKEN_SUFFIX;
     } else {
         $token = $request->getSessionData('wsEditToken');
         if ($token === null) {
             $token = MWCryptRand::generateHex(32);
             $request->setSessionData('wsEditToken', $token);
         }
         if (is_array($salt)) {
             $salt = implode('|', $salt);
         }
         return hash_hmac('md5', $timestamp . $salt, $token, false) . dechex($timestamp) . self::EDIT_TOKEN_SUFFIX;
     }
 }
开发者ID:jpena88,项目名称:mediawiki-dokku-deploy,代码行数:25,代码来源:User.php


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