本文整理汇总了PHP中OCP\IUserSession::setUser方法的典型用法代码示例。如果您正苦于以下问题:PHP IUserSession::setUser方法的具体用法?PHP IUserSession::setUser怎么用?PHP IUserSession::setUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\IUserSession
的用法示例。
在下文中一共展示了IUserSession::setUser方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetApps
public function testGetApps()
{
$user = $this->generateUsers();
$this->groupManager->get('admin')->addUser($user);
$this->userSession->setUser($user);
$result = $this->api->getApps([]);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals(count(\OC_App::listAllApps()), count($data['apps']));
}
示例2: impersonate
/**
* become another user
* @UseSession
*/
public function impersonate($userid)
{
$users = $this->userManager->search($userid, 1, 0);
if (count($users) > 0) {
$user = array_shift($users);
if (strcasecmp($user->getUID(), $userid) === 0) {
$this->userSession->setUser($user);
}
}
return new JSONResponse();
}
示例3: testGetApps
public function testGetApps()
{
$this->ocsClient->expects($this->any())->method($this->anything())->will($this->returnValue(null));
$user = $this->generateUsers();
$this->groupManager->get('admin')->addUser($user);
$this->userSession->setUser($user);
$result = $this->api->getApps([]);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals(count(\OC_App::listAllApps(false, true, $this->ocsClient)), count($data['apps']));
}
示例4: impersonate
/**
* become another user
* @param string $userid
* @UseSession
* @return JSONResponse
*/
public function impersonate($userid)
{
$oldUserId = $this->userSession->getUser()->getUID();
$this->logger->warning("User {$oldUserId} trying to impersonate user {$userid}", ['app' => 'impersonate']);
$user = $this->userManager->get($userid);
if ($user === null) {
return new JSONResponse("No user found for {$userid}", Http::STATUS_NOT_FOUND);
} else {
$this->logger->warning("changing to user {$userid}", ['app' => 'impersonate']);
$this->userSession->setUser($user);
}
return new JSONResponse();
}
示例5: setUpUserHome
/**
* @param string $userId
* @return \OCP\Files\Folder
* @throws SetUpException
*/
public function setUpUserHome($userId = null)
{
if (is_null($userId)) {
$user = $this->userSession->getUser();
} else {
$user = $this->userManager->get($userId);
}
if (is_null($user) || !$this->userManager->userExists($user->getUID())) {
throw new SetUpException('could not set up user home for ' . json_encode($user));
}
if ($user !== $this->userSession->getUser()) {
\OC_Util::tearDownFS();
$this->userSession->setUser($user);
}
\OC_Util::setupFS($user->getUID());
return $this->getOrCreateSubFolder($this->rootFolder, '/' . $user->getUID());
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$userId = $input->getArgument('user_id');
if (!empty($userId)) {
$user = $this->userManager->get($userId);
if (is_null($user)) {
$output->writeln("<error>user {$userId} not found</error>");
return;
}
$this->userSession->setUser($user);
$storageService = $this->userService;
} else {
$storageService = $this->globalService;
}
/** @var $mounts StorageConfig[] */
$mounts = $storageService->getAllStorages();
$this->listMounts($userId, $mounts, $input, $output);
}
示例7: setUp
public function setUp()
{
$app = new Application();
$container = $app->getContainer();
// reset backend
$um = $container->getServer()->getUserManager();
$this->userSession = $container->getServer()->getUserSession();
$um->clearBackends();
$um->registerBackend(new \OC_User_Database());
// create test user
$this->userName = 'test';
\OC_User::deleteUser($this->userName);
$um->createUser($this->userName, $this->userName);
\OC_Util::tearDownFS();
$this->userSession->setUser(null);
Filesystem::tearDown();
\OC_Util::setupFS($this->userName);
$this->userSession->setUser($um->get($this->userName));
$view = new \OC\Files\View('/' . $this->userName . '/files');
// setup files
$filesToCopy = array('documents' => array('document.pdf', 'document.docx', 'document.odt', 'document.txt'));
$count = 0;
foreach ($filesToCopy as $folder => $files) {
foreach ($files as $file) {
$imgData = file_get_contents(__DIR__ . '/data/' . $file);
$view->mkdir($folder);
$path = $folder . '/' . $file;
$view->file_put_contents($path, $imgData);
// set mtime to get fixed sorting with respect to recentFiles
$count++;
$view->touch($path, 1000 + $count);
}
}
list($storage, ) = $view->resolvePath('');
/** @var $storage Storage */
$this->storage = $storage;
$this->scanner = $storage->getScanner();
$this->scanner->scan('');
}
示例8: getStorageService
protected function getStorageService($userId)
{
if (!empty($userId)) {
$user = $this->userManager->get($userId);
if (is_null($user)) {
throw new NoUserException("user {$userId} not found");
}
$this->userSession->setUser($user);
return $this->userService;
} else {
return $this->globalService;
}
}
示例9: testSubAdminOfGroupAlreadySubAdmin
public function testSubAdminOfGroupAlreadySubAdmin()
{
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
$this->userSession->setUser($user1);
$this->groupManager->get('admin')->addUser($user1);
$group1 = $this->groupManager->createGroup($this->getUniqueID());
//Make user2 subadmin of group1
$_POST['groupid'] = $group1->getGID();
$result = $this->api->addSubAdmin(['userid' => $user2->getUID()]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
//Make user2 subadmin of group1 again
$_POST['groupid'] = $group1->getGID();
$result = $this->api->addSubAdmin(['userid' => $user2->getUID()]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$group1->delete();
}
示例10: testGetSubAdminsOfGroup
public function testGetSubAdminsOfGroup()
{
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
$this->userSession->setUser($user1);
$this->groupManager->get('admin')->addUser($user1);
$group1 = $this->groupManager->createGroup($this->getUniqueID());
\OC_SubAdmin::createSubAdmin($user2->getUID(), $group1->getGID());
$result = $this->api->getSubAdminsOfGroup(['groupid' => $group1->getGID()]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals($user2->getUID(), reset($data));
$group1->delete();
$user1 = $this->generateUsers();
$this->userSession->setUser($user1);
$this->groupManager->get('admin')->addUser($user1);
$result = $this->api->getSubAdminsOfGroup(['groupid' => $this->getUniqueID()]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(101, $result->getStatusCode());
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$userId = $input->getArgument('user_id');
if (!empty($userId)) {
$user = $this->userManager->get($userId);
if (is_null($user)) {
$output->writeln("<error>user {$userId} not found</error>");
return;
}
$this->userSession->setUser($user);
$storageService = $this->userService;
} else {
$storageService = $this->globalService;
}
/** @var $mounts StorageConfig[] */
$mounts = $storageService->getAllStorages();
if (count($mounts) === 0) {
if ($userId) {
$output->writeln("<info>No mounts configured by {$userId}</info>");
} else {
$output->writeln("<info>No admin mounts configured</info>");
}
return;
}
$headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options'];
if (!$userId) {
$headers[] = 'Applicable Users';
$headers[] = 'Applicable Groups';
}
if (!$input->getOption('show-password')) {
$hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key'];
foreach ($mounts as $mount) {
$config = $mount->getBackendOptions();
foreach ($config as $key => $value) {
if (in_array($key, $hideKeys)) {
$mount->setBackendOption($key, '***');
}
}
}
}
$outputType = $input->getOption('output');
if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
$keys = array_map(function ($header) {
return strtolower(str_replace(' ', '_', $header));
}, $headers);
$pairs = array_map(function (StorageConfig $config) use($keys, $userId) {
$values = [$config->getId(), $config->getMountPoint(), $config->getBackend()->getStorageClass(), $config->getAuthMechanism()->getScheme(), $config->getBackendOptions(), $config->getMountOptions()];
if (!$userId) {
$values[] = $config->getApplicableUsers();
$values[] = $config->getApplicableGroups();
}
return array_combine($keys, $values);
}, $mounts);
if ($outputType === self::OUTPUT_FORMAT_JSON) {
$output->writeln(json_encode(array_values($pairs)));
} else {
$output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
}
} else {
$full = $input->getOption('full');
$defaultMountOptions = ['encrypt' => true, 'previews' => true, 'filesystem_check_changes' => 1];
$rows = array_map(function (StorageConfig $config) use($userId, $defaultMountOptions, $full) {
$storageConfig = $config->getBackendOptions();
$keys = array_keys($storageConfig);
$values = array_values($storageConfig);
if (!$full) {
$values = array_map(function ($value) {
if (is_string($value) && strlen($value) > 32) {
return substr($value, 0, 6) . '...' . substr($value, -6, 6);
} else {
return $value;
}
}, $values);
}
$configStrings = array_map(function ($key, $value) {
return $key . ': ' . json_encode($value);
}, $keys, $values);
$configString = implode(', ', $configStrings);
$mountOptions = $config->getMountOptions();
// hide defaults
foreach ($mountOptions as $key => $value) {
if ($value === $defaultMountOptions[$key]) {
unset($mountOptions[$key]);
}
}
$keys = array_keys($mountOptions);
$values = array_values($mountOptions);
$optionsStrings = array_map(function ($key, $value) {
return $key . ': ' . json_encode($value);
}, $keys, $values);
$optionsString = implode(', ', $optionsStrings);
$values = [$config->getId(), $config->getMountPoint(), $config->getBackend()->getText(), $config->getAuthMechanism()->getText(), $configString, $optionsString];
if (!$userId) {
$applicableUsers = implode(', ', $config->getApplicableUsers());
$applicableGroups = implode(', ', $config->getApplicableGroups());
if ($applicableUsers === '' && $applicableGroups === '') {
$applicableUsers = 'All';
}
$values[] = $applicableUsers;
$values[] = $applicableGroups;
//.........这里部分代码省略.........