本文整理汇总了PHP中OCP\ISession类的典型用法代码示例。如果您正苦于以下问题:PHP ISession类的具体用法?PHP ISession怎么用?PHP ISession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ISession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
*
*/
protected function setUp()
{
parent::setUp();
$this->sessionMock = $this->getMock('OCP\\ISession');
$this->sessionMock->expects($this->any())->method('set')->will($this->returnCallback([$this, "setValueTester"]));
$this->sessionMock->expects($this->any())->method('get')->will($this->returnCallback([$this, "getValueTester"]));
$this->sessionMock->expects($this->any())->method('remove')->will($this->returnCallback([$this, "removeValueTester"]));
$this->instance = new Session($this->sessionMock);
}
示例2: testUnwrappingGet
public function testUnwrappingGet()
{
$unencryptedValue = 'foobar';
$encryptedValue = $this->crypto->encrypt($unencryptedValue);
$this->wrappedSession->expects($this->once())->method('get')->with('encrypted_session_data')->willReturnCallback(function () use($encryptedValue) {
return $encryptedValue;
});
$this->assertSame($unencryptedValue, $this->wrappedSession->get('encrypted_session_data'));
}
示例3: manipulateStorageConfig
public function manipulateStorageConfig(StorageConfig &$storage)
{
$encrypted = $this->session->get('password::sessioncredentials/credentials');
if (!isset($encrypted)) {
throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved');
}
$credentials = json_decode($this->crypto->decrypt($encrypted), true);
$storage->setBackendOption('user', $this->session->get('loginname'));
$storage->setBackendOption('password', $credentials['password']);
}
示例4: testShowLoginFormWithErrorsInSession
public function testShowLoginFormWithErrorsInSession()
{
$this->userSession->expects($this->once())->method('isLoggedIn')->willReturn(false);
$this->session->expects($this->once())->method('get')->with('loginMessages')->willReturn([['ErrorArray1', 'ErrorArray2'], ['MessageArray1', 'MessageArray2']]);
$expectedResponse = new TemplateResponse('core', 'login', ['ErrorArray1' => true, 'ErrorArray2' => true, 'messages' => ['MessageArray1', 'MessageArray2'], 'loginName' => '', 'user_autofocus' => true, 'canResetPassword' => true, 'alt_login' => [], 'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(), 'rememberLoginState' => 0], 'guest');
$this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '', ''));
}
示例5: create
/**
* @NoAdminRequired
* @NoSubadminRequired
*
* @return JSONResponse
*/
public function create($name)
{
try {
$sessionId = $this->session->getId();
} catch (SessionNotAvailableException $ex) {
$resp = new JSONResponse();
$resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
return $resp;
}
try {
$sessionToken = $this->tokenProvider->getToken($sessionId);
$loginName = $sessionToken->getLoginName();
try {
$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
} catch (PasswordlessTokenException $ex) {
$password = null;
}
} catch (InvalidTokenException $ex) {
$resp = new JSONResponse();
$resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
return $resp;
}
$token = $this->generateRandomDeviceToken();
$deviceToken = $this->tokenProvider->generateToken($token, $this->uid, $loginName, $password, $name, IToken::PERMANENT_TOKEN);
return ['token' => $token, 'deviceToken' => $deviceToken];
}
示例6: proxy
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $src
*
* TODO: Cache the proxied content to prevent unnecessary requests from the oC server
* The caching should also already happen in a cronjob so that the sender of the
* mail does not know whether the mail has been opened.
*
* @return ProxyDownloadResponse
*/
public function proxy($src)
{
// close the session to allow parallel downloads
$this->session->close();
$content = $this->helper->getUrlContent($src);
return new ProxyDownloadResponse($content, $src, 'application/octet-stream');
}
示例7: checkSession
/**
* Makes sure the user is already properly authenticated when a password is required and none
* was provided
*
* @param array|bool $linkItem
*
* @throws CheckException
*/
private function checkSession($linkItem)
{
// Not authenticated ?
if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== $linkItem['id']) {
throw new CheckException("Missing password", Http::STATUS_UNAUTHORIZED);
}
}
示例8: checkSession
/**
* Makes sure the user is already properly authenticated when a password is required and none
* was provided
*
* @param IShare $share
*
* @throws CheckException
*/
private function checkSession($share)
{
// Not authenticated ?
if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== (string) $share->getId()) {
throw new CheckException("Missing password", Http::STATUS_UNAUTHORIZED);
}
}
示例9: getTimeZone
/**
* Get the timezone of the current user, based on his session information and config data
*
* @param bool|int $timestamp
* @return \DateTimeZone
*/
public function getTimeZone($timestamp = false)
{
$timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
if ($timeZone === null) {
if ($this->session->exists('timezone')) {
return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
}
$timeZone = $this->getDefaultTimeZone();
}
try {
return new \DateTimeZone($timeZone);
} catch (\Exception $e) {
\OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG);
return new \DateTimeZone($this->getDefaultTimeZone());
}
}
示例10: proxy
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* TODO: Cache the proxied content to prevent unnecessary requests from the oC server
* The caching should also already happen in a cronjob so that the sender of the
* mail does not know whether the mail has been opened.
*
* @return ProxyDownloadResponse
*/
public function proxy()
{
// close the session to allow parallel downloads
$this->session->close();
$resourceURL = $this->request->getParam('src');
$content = \OC::$server->getHelper()->getUrlContent($resourceURL);
return new ProxyDownloadResponse($content, $resourceURL, 'application/octet-stream');
}
示例11: clear
/**
* remove keys from session
*/
public function clear()
{
$this->session->remove('publicSharePrivateKey');
$this->session->remove('privateKey');
$this->session->remove('encryptionInitialized');
$this->session->remove('decryptAll');
$this->session->remove('decryptAllKey');
$this->session->remove('decryptAllUid');
}
示例12: close
/**
* Close the session and release the lock, also writes all changed data in batch
*/
public function close()
{
if ($this->isModified) {
$encryptedValue = $this->crypto->encrypt(json_encode($this->sessionValues), $this->passphrase);
$this->session->set(self::encryptedSessionName, $encryptedValue);
$this->isModified = false;
}
$this->session->close();
}
示例13: testAuthenticateAlreadyLoggedIn
public function testAuthenticateAlreadyLoggedIn()
{
$server = $this->getMockBuilder('\\Sabre\\DAV\\Server')->disableOriginalConstructor()->getMock();
$this->userSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
$this->session->expects($this->once())->method('get')->with('AUTHENTICATED_TO_DAV_BACKEND')->will($this->returnValue(null));
$user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
$user->expects($this->once())->method('getUID')->will($this->returnValue('MyWrongDavUser'));
$this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($user));
$this->session->expects($this->once())->method('close');
$this->assertTrue($this->auth->authenticate($server, 'TestRealm'));
}
示例14: auth
/**
* @param \Sabre\DAV\Server $server
* @param $realm
* @return bool
*/
private function auth(\Sabre\DAV\Server $server, $realm)
{
if (\OC_User::handleApacheAuth() || $this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) {
$user = $this->userSession->getUser()->getUID();
\OC_Util::setupFS($user);
$this->currentUser = $user;
$this->session->close();
return true;
}
return parent::authenticate($server, $realm);
}
示例15: testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjaxButUserIsStillLoggedIn
public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjaxButUserIsStillLoggedIn()
{
/** @var \Sabre\HTTP\RequestInterface $httpRequest */
$httpRequest = $this->getMockBuilder('\\Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock();
/** @var \Sabre\HTTP\ResponseInterface $httpResponse */
$httpResponse = $this->getMockBuilder('\\Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
$this->userSession->expects($this->any())->method('isLoggedIn')->will($this->returnValue(true));
$this->session->expects($this->once())->method('get')->with('AUTHENTICATED_TO_DAV_BACKEND')->will($this->returnValue('MyTestUser'));
$httpRequest->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue(null));
$this->auth->check($httpRequest, $httpResponse);
}