本文整理汇总了PHP中OCP\IUserSession::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP IUserSession::getUser方法的具体用法?PHP IUserSession::getUser怎么用?PHP IUserSession::getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\IUserSession
的用法示例。
在下文中一共展示了IUserSession::getUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isEnabledForUser
/**
* Check if an app is enabled for user
*
* @param string $appId
* @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used
* @return bool
*/
public function isEnabledForUser($appId, $user = null)
{
if (is_null($user)) {
$user = $this->userSession->getUser();
}
$installedApps = $this->getInstalledApps();
if (isset($installedApps[$appId])) {
$enabled = $installedApps[$appId];
if ($enabled === 'yes') {
return true;
} elseif (is_null($user)) {
return false;
} else {
$groupIds = json_decode($enabled);
$userGroups = $this->groupManager->getUserGroupIds($user);
foreach ($userGroups as $groupId) {
if (array_search($groupId, $groupIds) !== false) {
return true;
}
}
return false;
}
} else {
return false;
}
}
示例2: load
/**
* Create a new \OCP\ITags instance and load tags from db.
*
* @see \OCP\ITags
* @param string $type The type identifier e.g. 'contact' or 'event'.
* @param array $defaultTags An array of default tags to be used if none are stored.
* @param boolean $includeShared Whether to include tags for items shared with this user by others.
* @param string $userId user for which to retrieve the tags, defaults to the currently
* logged in user
* @return \OCP\ITags
*/
public function load($type, $defaultTags = array(), $includeShared = false, $userId = null)
{
if (is_null($userId)) {
$userId = $this->userSession->getUser()->getUId();
}
return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
}
示例3: index
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function index()
{
$userId = $this->userSession->getUser()->getUID();
$appVersion = $this->config->getAppValue($this->appName, 'installed_version');
$defaultView = $this->config->getUserValue($userId, $this->appName, 'currentView', 'month');
return new TemplateResponse('calendar', 'main', ['appVersion' => $appVersion, 'defaultView' => $defaultView]);
}
示例4: updatePrivateKeyPassword
/**
* @NoAdminRequired
* @UseSession
*
* @param string $oldPassword
* @param string $newPassword
* @return DataResponse
*/
public function updatePrivateKeyPassword($oldPassword, $newPassword)
{
$result = false;
$uid = $this->userSession->getUser()->getUID();
$errorMessage = $this->l->t('Could not update the private key password.');
//check if password is correct
$passwordCorrect = $this->userManager->checkPassword($uid, $newPassword);
if ($passwordCorrect !== false) {
$encryptedKey = $this->keyManager->getPrivateKey($uid);
$decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword);
if ($decryptedKey) {
$encryptedKey = $this->crypt->symmetricEncryptFileContent($decryptedKey, $newPassword);
$header = $this->crypt->generateHeader();
if ($encryptedKey) {
$this->keyManager->setPrivateKey($uid, $header . $encryptedKey);
$this->session->setPrivateKey($decryptedKey);
$result = true;
}
} else {
$errorMessage = $this->l->t('The old password was not correct, please try again.');
}
} else {
$errorMessage = $this->l->t('The current log-in password was not correct, please try again.');
}
if ($result === true) {
$this->session->setStatus(Session::INIT_SUCCESSFUL);
return new DataResponse(['message' => (string) $this->l->t('Private key password successfully updated.')]);
} else {
return new DataResponse(['message' => (string) $errorMessage], Http::STATUS_BAD_REQUEST);
}
}
示例5: getUser
/**
* @return IUser|null
*/
protected function getUser()
{
if ($this->user) {
return $this->user;
}
return $this->userSession->getUser();
}
示例6: getGroup
/**
* returns an array of users in the group specified
*
* @param array $parameters
* @return OC_OCS_Result
*/
public function getGroup($parameters)
{
// Check if user is logged in
$user = $this->userSession->getUser();
if ($user === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
}
$groupId = $parameters['groupid'];
// Check the group exists
if (!$this->groupManager->groupExists($groupId)) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found');
}
$isSubadminOfGroup = false;
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group);
}
// Check subadmin has access to this group
if ($this->groupManager->isAdmin($user->getUID()) || $isSubadminOfGroup) {
$users = $this->groupManager->get($groupId)->getUsers();
$users = array_map(function ($user) {
/** @var IUser $user */
return $user->getUID();
}, $users);
$users = array_values($users);
return new OC_OCS_Result(['users' => $users]);
} else {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'User does not have access to specified group');
}
}
示例7: isAdmin
/**
* Returns whether the currently logged in user is an administrator
*/
private function isAdmin()
{
$user = $this->userSession->getUser();
if ($user !== null) {
return $this->groupManager->isAdmin($user->getUID());
}
return false;
}
示例8: index
/**
* @NoAdminRequired
*
* @param string $pattern
* @param bool $filterGroups
* @return DataResponse
*/
public function index($pattern = '', $filterGroups = false)
{
$groupPattern = $filterGroups ? $pattern : '';
$groupsInfo = new \OC\Group\MetaData($this->userSession->getUser()->getUID(), $this->isAdmin, $this->groupManager);
$groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT);
list($adminGroups, $groups) = $groupsInfo->get($groupPattern, $pattern);
return new DataResponse(array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups)));
}
示例9: getFilesByTag
/**
* Updates the tags of the specified file path.
* The passed tags are absolute, which means they will
* replace the actual tag selection.
*
* @param array $tagName tag name to filter by
* @return FileInfo[] list of matching files
* @throws \Exception if the tag does not exist
*/
public function getFilesByTag($tagName)
{
$nodes = $this->homeFolder->searchByTag($tagName, $this->userSession->getUser()->getUId());
foreach ($nodes as &$node) {
$node = $node->getFileInfo();
}
return $nodes;
}
示例10: manipulateStorageConfig
protected function manipulateStorageConfig(StorageConfig $storage)
{
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
}
示例11: logout
/**
* @NoAdminRequired
* @UseSession
*
* @return RedirectResponse
*/
public function logout()
{
$loginToken = $this->request->getCookie('oc_token');
if (!is_null($loginToken)) {
$this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken);
}
$this->userSession->logout();
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
示例12: getView
/**
* get a config value
*
* @return JSONResponse
*
* @NoAdminRequired
*/
public function getView()
{
$userId = $this->userSession->getUser()->getUID();
$app = $this->appName;
try {
$view = $this->config->getUserValue($userId, $app, 'currentView', 'month');
} catch (\Exception $e) {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new JSONResponse(['value' => $view]);
}
示例13: load
/**
* Create a new \OCP\ITags instance and load tags from db.
*
* @see \OCP\ITags
* @param string $type The type identifier e.g. 'contact' or 'event'.
* @param array $defaultTags An array of default tags to be used if none are stored.
* @param boolean $includeShared Whether to include tags for items shared with this user by others.
* @param string $userId user for which to retrieve the tags, defaults to the currently
* logged in user
* @return \OCP\ITags
*/
public function load($type, $defaultTags = array(), $includeShared = false, $userId = null)
{
if (is_null($userId)) {
$user = $this->userSession->getUser();
if ($user === null) {
// nothing we can do without a user
return null;
}
$userId = $this->userSession->getUser()->getUId();
}
return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
}
示例14: initCollections
/**
* initializes the collection. At this point of time, we need the logged in
* user. Since it is not the case when the instance is created, we cannot
* have this in the constructor.
*
* @throws NotAuthenticated
*/
protected function initCollections()
{
if (!empty($this->entityTypeCollections)) {
return;
}
$user = $this->userSession->getUser();
if (is_null($user)) {
throw new NotAuthenticated();
}
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$this->entityTypeCollections['files'] = new EntityTypeCollection('files', $this->commentsManager, $userFolder, $this->userManager, $this->logger);
}
示例15: 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();
}