本文整理汇总了PHP中OCP\IUserManager::userExists方法的典型用法代码示例。如果您正苦于以下问题:PHP IUserManager::userExists方法的具体用法?PHP IUserManager::userExists怎么用?PHP IUserManager::userExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\IUserManager
的用法示例。
在下文中一共展示了IUserManager::userExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decryptAll
/**
* start to decrypt all files
*
* @param InputInterface $input
* @param OutputInterface $output
* @param string $user which users data folder should be decrypted, default = all users
* @return bool
* @throws \Exception
*/
public function decryptAll(InputInterface $input, OutputInterface $output, $user = '')
{
$this->input = $input;
$this->output = $output;
if (!empty($user) && $this->userManager->userExists($user) === false) {
$this->output->writeln('User "' . $user . '" does not exist. Please check the username and try again');
return false;
}
$this->output->writeln('prepare encryption modules...');
if ($this->prepareEncryptionModules($user) === false) {
return false;
}
$this->output->writeln(' done.');
$this->decryptAllUsersFiles($user);
if (empty($this->failed)) {
$this->output->writeln('all files could be decrypted successfully!');
} else {
$this->output->writeln('Files for following users couldn\'t be decrypted, ');
$this->output->writeln('maybe the user is not set up in a way that supports this operation: ');
foreach ($this->failed as $uid => $paths) {
$this->output->writeln(' ' . $uid);
}
$this->output->writeln('');
}
return true;
}
示例2: getAvatar
/**
* return a user specific instance of \OCP\IAvatar
* @see \OCP\IAvatar
* @param string $user the ownCloud user id
* @return \OCP\IAvatar
* @throws \Exception In case the username is potentially dangerous
*/
public function getAvatar($user)
{
if (!$this->userManager->userExists($user)) {
throw new \Exception('user does not exist');
}
return new Avatar($this->rootFolder->getUserFolder($user)->getParent(), $this->l);
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->sourceUser = $input->getArgument('source-user');
$this->destinationUser = $input->getArgument('destination-user');
if (!$this->userManager->userExists($this->sourceUser)) {
$output->writeln("<error>Unknown source user {$this->sourceUser}</error>");
return;
}
if (!$this->userManager->userExists($this->destinationUser)) {
$output->writeln("<error>Unknown destination user {$this->destinationUser}</error>");
return;
}
$date = date('c');
$this->finalTarget = "{$this->destinationUser}/files/transferred from {$this->sourceUser} on {$date}";
// setup filesystem
Filesystem::initMountPoints($this->sourceUser);
Filesystem::initMountPoints($this->destinationUser);
// analyse source folder
$this->analyse($output);
// collect all the shares
$this->collectUsersShares($output);
// transfer the files
$this->transfer($output);
// restore the shares
$this->restoreShares($output);
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->sourceUser = $input->getArgument('source-user');
$this->destinationUser = $input->getArgument('destination-user');
if (!$this->userManager->userExists($this->sourceUser)) {
$output->writeln("<error>Unknown source user {$this->sourceUser}</error>");
return;
}
if (!$this->userManager->userExists($this->destinationUser)) {
$output->writeln("<error>Unknown destination user {$this->destinationUser}</error>");
return;
}
// target user has to be ready
if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
$output->writeln("<error>The target user is not ready to accept files. The user has at least to be logged in once.</error>");
return;
}
$date = date('c');
$this->finalTarget = "{$this->destinationUser}/files/transferred from {$this->sourceUser} on {$date}";
// setup filesystem
Filesystem::initMountPoints($this->sourceUser);
Filesystem::initMountPoints($this->destinationUser);
// analyse source folder
$this->analyse($output);
// collect all the shares
$this->collectUsersShares($output);
// transfer the files
$this->transfer($output);
// restore the shares
$this->restoreShares($output);
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$users = $input->getArgument('user_id');
if (!empty($users)) {
foreach ($users as $user) {
if ($this->userManager->userExists($user)) {
$output->writeln("Delete versions of <info>{$user}</info>");
$this->deleteVersions($user);
} else {
$output->writeln("<error>Unknown user {$user}</error>");
}
}
} else {
$output->writeln('Delete all versions');
foreach ($this->userManager->getBackends() as $backend) {
$name = get_class($backend);
if ($backend instanceof IUserBackend) {
$name = $backend->getBackendName();
}
$output->writeln("Delete versions for users on backend <info>{$name}</info>");
$limit = 500;
$offset = 0;
do {
$users = $backend->getUsers('', $limit, $offset);
foreach ($users as $user) {
$output->writeln(" <info>{$user}</info>");
$this->deleteVersions($user);
}
$offset += $limit;
} while (count($users) >= $limit);
}
}
}
示例6: setupFS
/**
* Act on behalf on trash item owner
* @param string $user
* @return boolean
*/
private function setupFS($user)
{
if (!$this->userManager->userExists($user)) {
return false;
}
\OC_Util::tearDownFS();
\OC_Util::setupFS($user);
return true;
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user');
if (!$this->userManager->userExists($user)) {
throw new \InvalidArgumentException("User <{$user}> in unknown.");
}
$name = $input->getArgument('name');
$this->cardDavBackend->createAddressBook("principals/users/{$user}", $name, []);
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user');
if (!$this->userManager->userExists($user)) {
throw new \InvalidArgumentException("User <{$user}> in unknown.");
}
$name = $input->getArgument('name');
$caldav = new CalDavBackend($this->dbConnection);
$caldav->createCalendar("principals/{$user}", $name, []);
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user');
if (!$this->userManager->userExists($user)) {
throw new \InvalidArgumentException("User <{$user}> in unknown.");
}
$principalBackend = new Principal($this->userManager, $this->groupManager);
$name = $input->getArgument('name');
$carddav = new CardDavBackend($this->dbConnection, $principalBackend, $this->logger);
$carddav->createAddressBook("principals/users/{$user}", $name, []);
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$uid = $input->getArgument('uid');
if ($this->userManager->userExists($uid)) {
$output->writeln('<error>The user "' . $uid . '" already exists.</error>');
return 1;
}
if ($input->getOption('password-from-env')) {
$password = getenv('OC_PASS');
if (!$password) {
$output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>');
return 1;
}
} elseif ($input->isInteractive()) {
/** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
$dialog = $this->getHelperSet()->get('dialog');
$password = $dialog->askHiddenResponse($output, '<question>Enter password: </question>', false);
$confirm = $dialog->askHiddenResponse($output, '<question>Confirm password: </question>', false);
if ($password !== $confirm) {
$output->writeln("<error>Passwords did not match!</error>");
return 1;
}
} else {
$output->writeln("<error>Interactive input or --password-from-env is needed for entering a password!</error>");
return 1;
}
$user = $this->userManager->createUser($input->getArgument('uid'), $password);
if ($user instanceof IUser) {
$output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>');
} else {
$output->writeln('<error>An error occurred while creating the user</error>');
return 1;
}
if ($input->getOption('display-name')) {
$user->setDisplayName($input->getOption('display-name'));
$output->writeln('Display name set to "' . $user->getDisplayName() . '"');
}
$groups = $input->getOption('group');
if (!empty($groups)) {
// Make sure we init the Filesystem for the user, in case we need to
// init some group shares.
Filesystem::init($user->getUID(), '');
}
foreach ($groups as $groupName) {
$group = $this->groupManager->get($groupName);
if (!$group) {
$this->groupManager->createGroup($groupName);
$group = $this->groupManager->get($groupName);
$output->writeln('Created group "' . $group->getGID() . '"');
}
$group->addUser($user);
$output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"');
}
}
示例11: delete
/**
* Delete a share (owner unShares the file)
*
* @param IShare $share
*/
public function delete(IShare $share)
{
list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
$isOwner = false;
// if the local user is the owner we can send the unShare request directly...
if ($this->userManager->userExists($share->getShareOwner())) {
$this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
$this->revokeShare($share, true);
$isOwner = true;
} else {
// ... if not we need to correct ID for the unShare request
$remoteId = $this->getRemoteId($share);
$this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken());
$this->revokeShare($share, false);
}
// send revoke notification to the other user, if initiator and owner are not the same user
if ($share->getShareOwner() !== $share->getSharedBy()) {
$remoteId = $this->getRemoteId($share);
if ($isOwner) {
list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
} else {
list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
}
$this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken());
}
$this->removeShareFromTable($share);
}
示例12: create
/**
* @NoAdminRequired
*
* @param string $username
* @param string $password
* @param array $groups
* @param string $email
* @return DataResponse
*/
public function create($username, $password, array $groups = array(), $email = '')
{
if ($email !== '' && !$this->mail->validateAddress($email)) {
return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mail address')), Http::STATUS_UNPROCESSABLE_ENTITY);
}
if (!$this->isAdmin) {
$userId = $this->userSession->getUser()->getUID();
if (!empty($groups)) {
foreach ($groups as $key => $group) {
if (!$this->subAdminFactory->isGroupAccessible($userId, $group)) {
unset($groups[$key]);
}
}
}
if (empty($groups)) {
$groups = $this->subAdminFactory->getSubAdminsOfGroups($userId);
}
}
if ($this->userManager->userExists($username)) {
return new DataResponse(array('message' => (string) $this->l10n->t('A user with that name already exists.')), Http::STATUS_CONFLICT);
}
try {
$user = $this->userManager->createUser($username, $password);
} catch (\Exception $exception) {
return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
}
if ($user instanceof User) {
if ($groups !== null) {
foreach ($groups as $groupName) {
$group = $this->groupManager->get($groupName);
if (empty($group)) {
$group = $this->groupManager->createGroup($groupName);
}
$group->addUser($user);
}
}
/**
* Send new user mail only if a mail is set
*/
if ($email !== '') {
$this->config->setUserValue($username, 'settings', 'email', $email);
// data for the mail template
$mailData = array('username' => $username, 'url' => $this->urlGenerator->getAbsoluteURL('/'));
$mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
$mailContent = $mail->render();
$mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
$plainTextMailContent = $mail->render();
$subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
try {
$this->mail->send($email, $username, $subject, $mailContent, $this->fromMailAddress, $this->defaults->getName(), 1, $plainTextMailContent);
} catch (\Exception $e) {
$this->log->error("Can't send new user mail to {$email}: " . $e->getMessage(), array('app' => 'settings'));
}
}
// fetch users groups
$userGroups = $this->groupManager->getUserGroupIds($user);
return new DataResponse($this->formatUserForIndex($user, $userGroups), Http::STATUS_CREATED);
}
return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
}
示例13: getAvatar
/**
* @NoCSRFRequired
* @PublicPage
*
* @param string $userId
* @param int $size
* @return DataResponse|DataDisplayResponse
*/
public function getAvatar($userId, $size)
{
if (!$this->userManager->userExists($userId)) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($size > 2048) {
$size = 2048;
} elseif ($size <= 0) {
$size = 64;
}
$avatar = $this->avatarManager->getAvatar($userId);
$image = $avatar->get($size);
if ($image instanceof \OCP\IImage) {
$resp = new DataDisplayResponse($image->data(), Http::STATUS_OK, ['Content-Type' => $image->mimeType()]);
$resp->setETag(crc32($image->data()));
} else {
$user = $this->userManager->get($userId);
$userName = $user ? $user->getDisplayName() : '';
$resp = new DataResponse(['data' => ['displayname' => $userName]]);
}
$resp->addHeader('Pragma', 'public');
$resp->cacheFor(0);
$resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
return $resp;
}
示例14: getCorrectUid
/**
* check if we are the initiator or the owner of a re-share and return the correct UID
*
* @param Share\IShare $share
* @return string
*/
protected function getCorrectUid(Share\IShare $share)
{
if ($this->userManager->userExists($share->getShareOwner())) {
return $share->getShareOwner();
}
return $share->getSharedBy();
}
示例15: checkTags
protected function checkTags($offset)
{
$query = $this->connection->getQueryBuilder();
$query->select('uid')->from('vcategory')->groupBy('uid')->orderBy('uid')->setMaxResults(50)->setFirstResult($offset);
$result = $query->execute();
$users = [];
$hadResults = false;
while ($row = $result->fetch()) {
$hadResults = true;
if (!$this->userManager->userExists($row['uid'])) {
$users[] = $row['uid'];
}
}
$result->closeCursor();
if (!$hadResults) {
// No more tags, stop looping
return false;
}
if (!empty($users)) {
$query = $this->connection->getQueryBuilder();
$query->delete('vcategory')->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY)));
$this->deletedTags += $query->execute();
}
return true;
}