예제 #1
0
 /**
  * @param IEvent $event
  * @param string $parameter The parameter to be formatted
  * @param bool $allowHtml   Should HTML be used to format the parameter?
  * @param bool $verbose     Should paths, names, etc be shortened or full length
  * @return string The formatted parameter
  */
 public function format(IEvent $event, $parameter, $allowHtml, $verbose = false)
 {
     // If the username is empty, the action has been performed by a remote
     // user, or via a public share. We don't know the username in that case
     if ($parameter === '') {
         if ($allowHtml === null) {
             return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>';
         }
         if ($allowHtml) {
             return '<strong>' . $this->l->t('"remote user"') . '</strong>';
         } else {
             return $this->l->t('"remote user"');
         }
     }
     $user = $this->manager->get($parameter);
     $displayName = $user ? $user->getDisplayName() : $parameter;
     $parameter = Util::sanitizeHTML($parameter);
     if ($allowHtml === null) {
         return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>';
     }
     if ($allowHtml) {
         $avatarPlaceholder = '';
         if ($this->config->getSystemValue('enable_avatars', true)) {
             $avatarPlaceholder = '<div class="avatar" data-user="******"></div>';
         }
         return $avatarPlaceholder . '<strong>' . Util::sanitizeHTML($displayName) . '</strong>';
     } else {
         return $displayName;
     }
 }
예제 #2
0
 /**
  * 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($userId)
 {
     $user = $this->userManager->get($userId);
     if (is_null($user)) {
         throw new \Exception('user does not exist');
     }
     return new Avatar($this->rootFolder->getUserFolder($userId)->getParent(), $this->l, $user);
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $this->userManager->get($input->getArgument('uid'));
     if (is_null($user)) {
         $output->writeln('<error>User does not exist</error>');
         return;
     }
     $user->setEnabled(false);
     $output->writeln('<info>The specified user is disabled</info>');
 }
예제 #4
0
 /**
  * @param IEvent $event
  * @param string $parameter The parameter to be formatted
  * @return string The formatted parameter
  */
 public function format(IEvent $event, $parameter)
 {
     // If the username is empty, the action has been performed by a remote
     // user, or via a public share. We don't know the username in that case
     if ($parameter === '') {
         return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>';
     }
     $user = $this->manager->get($parameter);
     $displayName = $user ? $user->getDisplayName() : $parameter;
     $parameter = Util::sanitizeHTML($parameter);
     return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>';
 }
예제 #5
0
 /**
  * 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();
 }
예제 #6
0
파일: delete.php 프로젝트: alfrescoo/core
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $this->userManager->get($input->getArgument('uid'));
     if (is_null($user)) {
         $output->writeln('<error>User does not exist</error>');
         return;
     }
     if ($user->delete()) {
         $output->writeln('<info>The specified user was deleted</info>');
         return;
     }
     $output->writeln('<error>The specified user could not be deleted. Please check the logs.</error>');
 }
예제 #7
0
 /**
  * Lookup user display names
  *
  * @NoAdminRequired
  *
  * @param array $users
  *
  * @return JSONResponse
  */
 public function getDisplayNames($users)
 {
     $result = array();
     foreach ($users as $user) {
         $userObject = $this->userManager->get($user);
         if (is_object($userObject)) {
             $result[$user] = $userObject->getDisplayName();
         } else {
             $result[$user] = $user;
         }
     }
     $json = array('users' => $result, 'status' => 'success');
     return new JSONResponse($json);
 }
예제 #8
0
 /**
  * Returns a specific principal, specified by it's path.
  * The returned structure should be the exact same as from
  * getPrincipalsByPrefix.
  *
  * @param string $path
  * @return array
  */
 public function getPrincipalByPath($path)
 {
     list($prefix, $name) = explode('/', $path);
     $user = $this->userManager->get($name);
     if ($prefix === 'principals' && !is_null($user)) {
         $principal = ['uri' => 'principals/' . $user->getUID(), '{DAV:}displayname' => $user->getUID()];
         $email = $this->config->getUserValue($user->getUID(), 'settings', 'email');
         if ($email) {
             $principal['{http://sabredav.org/ns}email-address'] = $email;
         }
         return $principal;
     }
     return null;
 }
예제 #9
0
파일: share20ocs.php 프로젝트: gvde/core
 /**
  * Convert an IShare to an array for OCS output
  *
  * @param \OCP\Share\IShare $share
  * @return array
  * @throws NotFoundException In case the node can't be resolved.
  */
 protected function formatShare(\OCP\Share\IShare $share)
 {
     $sharedBy = $this->userManager->get($share->getSharedBy());
     $shareOwner = $this->userManager->get($share->getShareOwner());
     $result = ['id' => $share->getId(), 'share_type' => $share->getShareType(), 'uid_owner' => $share->getSharedBy(), 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), 'permissions' => $share->getPermissions(), 'stime' => $share->getShareTime()->getTimestamp(), 'parent' => null, 'expiration' => null, 'token' => null, 'uid_file_owner' => $share->getShareOwner(), 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner()];
     $node = $share->getNode();
     $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner())->getRelativePath($node->getPath());
     if ($node instanceof \OCP\Files\Folder) {
         $result['item_type'] = 'folder';
     } else {
         $result['item_type'] = 'file';
     }
     $result['storage_id'] = $node->getStorage()->getId();
     $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
     $result['item_source'] = $node->getId();
     $result['file_source'] = $node->getId();
     $result['file_parent'] = $node->getParent()->getId();
     $result['file_target'] = $share->getTarget();
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $sharedWith = $this->userManager->get($share->getSharedWith());
         $result['share_with'] = $share->getSharedWith();
         $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $result['share_with'] = $share->getSharedWith();
             $result['share_with_displayname'] = $share->getSharedWith();
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $result['share_with'] = $share->getPassword();
                 $result['share_with_displayname'] = $share->getPassword();
                 $result['token'] = $share->getToken();
                 $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
                 $expiration = $share->getExpirationDate();
                 if ($expiration !== null) {
                     $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
                 }
             } else {
                 if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
                     $result['share_with'] = $share->getSharedWith();
                     $result['share_with_displayname'] = $share->getSharedWith();
                     $result['token'] = $share->getToken();
                 }
             }
         }
     }
     $result['mail_send'] = $share->getMailSend() ? 1 : 0;
     return $result;
 }
예제 #10
0
 /**
  * @param string $user
  * @throws \Exception
  */
 protected function sendEmail($user)
 {
     if (!$this->userManager->userExists($user)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
     }
     $userObject = $this->userManager->get($user);
     $email = $userObject->getEMailAddress();
     if (empty($email)) {
         throw new \Exception($this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.'));
     }
     $token = $this->secureRandom->generate(21, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER);
     $this->config->setUserValue($user, 'owncloud', 'lostpassword', $this->timeFactory->getTime() . ':' . $token);
     $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user, 'token' => $token));
     $tmpl = new \OC_Template('core/lostpassword', 'email');
     $tmpl->assign('link', $link);
     $msg = $tmpl->fetchPage();
     try {
         $message = $this->mailer->createMessage();
         $message->setTo([$email => $user]);
         $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
         $message->setPlainBody($msg);
         $message->setFrom([$this->from => $this->defaults->getName()]);
         $this->mailer->send($message);
     } catch (\Exception $e) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.'));
     }
 }
예제 #11
0
 /**
  * Create a share object from an database row
  *
  * @param mixed[] $data
  * @return Share
  */
 private function createShare($data)
 {
     $share = new Share();
     $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setShareTime((int) $data['stime'])->setMailSend((bool) $data['mail_send']);
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $share->setSharedWith($this->userManager->get($data['share_with']));
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $share->setSharedWith($this->groupManager->get($data['share_with']));
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $share->setPassword($data['share_with']);
                 $share->setToken($data['token']);
             } else {
                 $share->setSharedWith($data['share_with']);
             }
         }
     }
     $share->setSharedBy($this->userManager->get($data['uid_owner']));
     // TODO: getById can return an array. How to handle this properly??
     $folder = $this->rootFolder->getUserFolder($share->getSharedBy()->getUID());
     $path = $folder->getById((int) $data['file_source'])[0];
     $owner = $path->getOwner();
     $share->setShareOwner($owner);
     $path = $this->rootFolder->getUserFolder($owner->getUID())->getById((int) $data['file_source'])[0];
     $share->setPath($path);
     if ($data['expiration'] !== null) {
         $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
         $share->setExpirationDate($expiration);
     }
     return $share;
 }
예제 #12
0
 /**
  * Prepares a user name parameter for usage
  *
  * Add an avatar to usernames
  *
  * @param string $param
  * @param bool $highlightParams
  * @return string
  */
 protected function prepareUserParam($param, $highlightParams)
 {
     // If the username is empty, the action has been performed by a remote
     // user, or via a public share. We don't know the username in that case
     if ($param === '') {
         if ($highlightParams) {
             return '<strong>' . $this->l->t('"remote user"') . '</strong>';
         } else {
             return $this->l->t('"remote user"');
         }
     }
     $user = $this->userManager->get($param);
     $displayName = $user ? $user->getDisplayName() : $param;
     $param = Util::sanitizeHTML($param);
     $displayName = Util::sanitizeHTML($displayName);
     if ($highlightParams) {
         $avatarPlaceholder = '';
         if ($this->config->getSystemValue('enable_avatars', true)) {
             $avatarPlaceholder = '<div class="avatar" data-user="******"></div>';
         }
         return $avatarPlaceholder . '<strong>' . $displayName . '</strong>';
     } else {
         return $displayName;
     }
 }
 /**
  * Send a notification to one user
  *
  * @param string $userName Username of the recipient
  * @param string $email Email address of the recipient
  * @param string $lang Selected language of the recipient
  * @param string $timezone Selected timezone of the recipient
  * @param int $maxTime
  */
 public function sendEmailToUser($userName, $email, $lang, $timezone, $maxTime)
 {
     $user = $this->userManager->get($userName);
     if (!$user instanceof IUser) {
         return;
     }
     list($mailData, $skippedCount) = $this->getItemsForUser($userName, $maxTime);
     $l = $this->getLanguage($lang);
     $this->dataHelper->setUser($userName);
     $this->dataHelper->setL10n($l);
     $activityList = array();
     foreach ($mailData as $activity) {
         $relativeDateTime = $this->dateFormatter->formatDateTimeRelativeDay($activity['amq_timestamp'], 'long', 'medium', new \DateTimeZone($timezone), $l);
         $activityList[] = array($this->dataHelper->translation($activity['amq_appid'], $activity['amq_subject'], $this->dataHelper->getParameters($activity['amq_subjectparams'])), $relativeDateTime);
     }
     $alttext = new Template('activity', 'email.notification', '');
     $alttext->assign('username', $user->getDisplayName());
     $alttext->assign('activities', $activityList);
     $alttext->assign('skippedCount', $skippedCount);
     $alttext->assign('owncloud_installation', $this->urlGenerator->getAbsoluteURL('/'));
     $alttext->assign('overwriteL10N', $l);
     $emailText = $alttext->fetchPage();
     $message = $this->mailer->createMessage();
     $message->setTo([$email => $user->getDisplayName()]);
     $message->setSubject((string) $l->t('Activity notification'));
     $message->setPlainBody($emailText);
     $message->setFrom([$this->getSenderData('email') => $this->getSenderData('name')]);
     $this->mailer->send($message);
 }
예제 #14
0
	/**
	 * @NoAdminRequired
	 *
	 * @param string $userId
	 * @param int $size
	 * @return DataResponse|DataDisplayResponse
	 */
	public function getAvatar($userId, $size) {
		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;
	}
예제 #15
0
 /**
  * perform login using the magic cookie (remember login)
  *
  * @param string $uid the username
  * @param string $currentToken
  * @return bool
  */
 public function loginWithCookie($uid, $currentToken)
 {
     $this->session->regenerateId();
     $this->manager->emit('\\OC\\User', 'preRememberedLogin', array($uid));
     $user = $this->manager->get($uid);
     if (is_null($user)) {
         // user does not exist
         return false;
     }
     // get stored tokens
     $tokens = OC::$server->getConfig()->getUserKeys($uid, 'login_token');
     // test cookies token against stored tokens
     if (!in_array($currentToken, $tokens, true)) {
         return false;
     }
     // replace successfully used token with a new one
     OC::$server->getConfig()->deleteUserValue($uid, 'login_token', $currentToken);
     $newToken = OC::$server->getSecureRandom()->generate(32);
     OC::$server->getConfig()->setUserValue($uid, 'login_token', $newToken, time());
     $this->setMagicInCookie($user->getUID(), $newToken);
     //login
     $this->setUser($user);
     $this->manager->emit('\\OC\\User', 'postRememberedLogin', array($user));
     return true;
 }
예제 #16
0
 /**
  * Returns a list of properties for this nodes.
  *
  * The properties list is a list of propertynames the client requested,
  * encoded in clark-notation {xmlnamespace}tagname
  *
  * If the array is empty, it means 'all properties' were requested.
  *
  * Note that it's fine to liberally give properties back, instead of
  * conforming to the list of requested properties.
  * The Server class will filter out the extra.
  *
  * @param array $properties
  * @return array
  */
 function getProperties($properties)
 {
     $properties = array_keys($this->properties);
     $result = [];
     foreach ($properties as $property) {
         $getter = $this->properties[$property];
         if (method_exists($this->comment, $getter)) {
             $result[$property] = $this->comment->{$getter}();
         }
     }
     if ($this->comment->getActorType() === 'users') {
         $user = $this->userManager->get($this->comment->getActorId());
         $displayName = is_null($user) ? null : $user->getDisplayName();
         $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName;
     }
     $unread = null;
     $user = $this->userSession->getUser();
     if (!is_null($user)) {
         $readUntil = $this->commentsManager->getReadMark($this->comment->getObjectType(), $this->comment->getObjectId(), $user);
         if (is_null($readUntil)) {
             $unread = 'true';
         } else {
             $unread = $this->comment->getCreationDateTime() > $readUntil;
             // re-format for output
             $unread = $unread ? 'true' : 'false';
         }
     }
     $result[self::PROPERTY_NAME_UNREAD] = $unread;
     return $result;
 }
예제 #17
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $this->userManager->get($input->getArgument('uid'));
     if (is_null($user)) {
         $output->writeln('<error>User does not exist</error>');
         return;
     }
     $lastLogin = $user->getLastLogin();
     if ($lastLogin === 0) {
         $output->writeln('User ' . $user->getUID() . ' has never logged in, yet.');
     } else {
         $date = new \DateTime();
         $date->setTimestamp($lastLogin);
         $output->writeln($user->getUID() . '`s last login: '******'d.m.Y H:i'));
     }
 }
예제 #18
0
 /**
  * return a user specific instance of \OCP\IAvatar
  * @see \OCP\IAvatar
  * @param string $userId the ownCloud user id
  * @return \OCP\IAvatar
  * @throws \Exception In case the username is potentially dangerous
  * @throws NotFoundException In case there is no user folder yet
  */
 public function getAvatar($userId)
 {
     $user = $this->userManager->get($userId);
     if (is_null($user)) {
         throw new \Exception('user does not exist');
     }
     /*
      * Fix for #22119
      * Basically we do not want to copy the skeleton folder
      */
     \OC\Files\Filesystem::initMountPoints($userId);
     $dir = '/' . $userId;
     /** @var Folder $folder */
     $folder = $this->rootFolder->get($dir);
     return new Avatar($folder, $this->l, $user, $this->logger);
 }
예제 #19
0
 /**
  * @PublicPage
  * @param string $token
  * @param string $userId
  * @param string $password
  * @param boolean $proceed
  * @return array
  */
 public function setPassword($token, $userId, $password, $proceed)
 {
     if ($this->isDataEncrypted && !$proceed) {
         return $this->error('', array('encryption' => true));
     }
     try {
         $user = $this->userManager->get($userId);
         $splittedToken = explode(':', $this->config->getUserValue($userId, 'owncloud', 'lostpassword', null));
         if (count($splittedToken) !== 2) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
         }
         if ($splittedToken[0] < $this->timeFactory->getTime() - 60 * 60 * 12 || $user->getLastLogin() > $splittedToken[0]) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
         }
         if (!StringUtils::equals($splittedToken[1], $token)) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
         }
         if (!$user->setPassword($password)) {
             throw new \Exception();
         }
         \OC_Hook::emit('\\OC\\Core\\LostPassword\\Controller\\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password));
         $this->config->deleteUserValue($userId, 'owncloud', 'lostpassword');
         @\OC_User::unsetMagicInCookie();
     } catch (\Exception $e) {
         return $this->error($e->getMessage());
     }
     return $this->success();
 }
예제 #20
0
 /**
  * Set the mail address of a user
  *
  * @NoAdminRequired
  * @NoSubadminRequired
  *
  * @param string $id
  * @param string $mailAddress
  * @return DataResponse
  */
 public function setMailAddress($id, $mailAddress)
 {
     $userId = $this->userSession->getUser()->getUID();
     if ($userId !== $id && !$this->isAdmin && !$this->subAdminFactory->isUserAccessible($userId, $id)) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Forbidden'))), Http::STATUS_FORBIDDEN);
     }
     if ($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid mail address'))), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     $user = $this->userManager->get($id);
     if (!$user) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid user'))), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     // this is the only permission a backend provides and is also used
     // for the permission of setting a email address
     if (!$user->canChangeDisplayName()) {
         return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Unable to change mail address'))), Http::STATUS_FORBIDDEN);
     }
     // delete user value if email address is empty
     if ($mailAddress === '') {
         $this->config->deleteUserValue($id, 'settings', 'email');
     } else {
         $this->config->setUserValue($id, 'settings', 'email', $mailAddress);
     }
     return new DataResponse(array('status' => 'success', 'data' => array('username' => $id, 'mailAddress' => $mailAddress, 'message' => (string) $this->l10n->t('Email saved'))), Http::STATUS_OK);
 }
예제 #21
0
 /**
  * Copied from \OC_Util::isSharingDisabledForUser
  *
  * TODO: Deprecate fuction from OC_Util
  *
  * @param string $userId
  * @return bool
  */
 public function sharingDisabledForUser($userId)
 {
     if ($userId === null) {
         return false;
     }
     if (isset($this->sharingDisabledForUsersCache[$userId])) {
         return $this->sharingDisabledForUsersCache[$userId];
     }
     if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
         $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
         $excludedGroups = json_decode($groupsList);
         if (is_null($excludedGroups)) {
             $excludedGroups = explode(',', $groupsList);
             $newValue = json_encode($excludedGroups);
             $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
         }
         $user = $this->userManager->get($userId);
         $usersGroups = $this->groupManager->getUserGroupIds($user);
         if (!empty($usersGroups)) {
             $remainingGroups = array_diff($usersGroups, $excludedGroups);
             // if the user is only in groups which are disabled for sharing then
             // sharing is also disabled for the user
             if (empty($remainingGroups)) {
                 $this->sharingDisabledForUsersCache[$userId] = true;
                 return true;
             }
         }
     }
     $this->sharingDisabledForUsersCache[$userId] = false;
     return false;
 }
예제 #22
0
 /**
  * @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());
 }
예제 #23
0
파일: listcommand.php 프로젝트: kenwi/core
 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);
 }
예제 #24
0
파일: userhooks.php 프로젝트: evanjt/core
 /**
  * If the password can't be changed within ownCloud, than update the key password in advance.
  *
  * @param array $params : uid, password
  * @return boolean|null
  */
 public function preSetPassphrase($params)
 {
     if (App::isEnabled('encryption')) {
         $user = $this->userManager->get($params['uid']);
         if ($user && !$user->canChangePassword()) {
             $this->setPassphrase($params);
         }
     }
 }
 /**
  * @NoAdminRequired
  * @NoSubadminRequired
  *
  * @return JSONResponse
  */
 public function destroy($id)
 {
     $user = $this->userManager->get($this->uid);
     if (is_null($user)) {
         return [];
     }
     $this->tokenProvider->invalidateTokenById($user, $id);
     return [];
 }
예제 #26
0
 /**
  * Create a share object from an database row
  *
  * @param mixed[] $data
  * @return \OCP\Share\IShare
  * @throws InvalidShare
  */
 private function createShare($data)
 {
     $share = new Share();
     $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setMailSend((bool) $data['mail_send']);
     $shareTime = new \DateTime();
     $shareTime->setTimestamp((int) $data['stime']);
     $share->setShareTime($shareTime);
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $sharedWith = $this->userManager->get($data['share_with']);
         if ($sharedWith === null) {
             throw new InvalidShare();
         }
         $share->setSharedWith($sharedWith);
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $sharedWith = $this->groupManager->get($data['share_with']);
             if ($sharedWith === null) {
                 throw new InvalidShare();
             }
             $share->setSharedWith($sharedWith);
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $share->setPassword($data['share_with']);
                 $share->setToken($data['token']);
             }
         }
     }
     if ($data['uid_initiator'] === null) {
         //OLD SHARE
         $sharedBy = $this->userManager->get($data['uid_owner']);
         if ($sharedBy === null) {
             throw new InvalidShare();
         }
         $share->setSharedBy($sharedBy);
         $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
         $owner = $path->getOwner();
         $share->setShareOwner($owner);
     } else {
         //New share!
         $sharedBy = $this->userManager->get($data['uid_initiator']);
         $shareOwner = $this->userManager->get($data['uid_owner']);
         if ($sharedBy === null || $shareOwner === null) {
             throw new InvalidShare();
         }
         $share->setSharedBy($sharedBy);
         $share->setShareOwner($shareOwner);
     }
     $path = $this->getNode($share->getShareOwner(), (int) $data['file_source']);
     $share->setNode($path);
     if ($data['expiration'] !== null) {
         $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
         $share->setExpirationDate($expiration);
     }
     $share->setProviderId($this->identifier());
     return $share;
 }
예제 #27
0
파일: subadmin.php 프로젝트: nem0xff/core
 /**
  * get all SubAdmins
  * @return array
  */
 public function getAllSubAdmins()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $result = $qb->select('*')->from('group_admin')->execute();
     $subadmins = [];
     while ($row = $result->fetch()) {
         $subadmins[] = ['user' => $this->userManager->get($row['uid']), 'group' => $this->groupManager->get($row['gid'])];
     }
     return $subadmins;
 }
예제 #28
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('user');
     /** @var $user \OCP\IUser */
     $user = $this->userManager->get($username);
     if (is_null($user)) {
         $output->writeln('<error>User does not exist</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');
         if (\OCP\App::isEnabled('encryption')) {
             $output->writeln('<error>Warning: Resetting the password when using encryption will result in data loss!</error>');
             if (!$dialog->askConfirmation($output, '<question>Do you want to continue?</question>', true)) {
                 return 1;
             }
         }
         $password = $dialog->askHiddenResponse($output, '<question>Enter a new password: </question>', false);
         $confirm = $dialog->askHiddenResponse($output, '<question>Confirm the new 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 new password!</error>");
         return 1;
     }
     $success = $user->setPassword($password);
     if ($success) {
         $output->writeln("<info>Successfully reset password for " . $username . "</info>");
     } else {
         $output->writeln("<error>Error while resetting password!</error>");
         return 1;
     }
 }
예제 #29
0
파일: sharees.php 프로젝트: gvde/core
 /**
  * @param string $search
  */
 protected function getUsers($search)
 {
     $this->result['users'] = $this->result['exact']['users'] = $users = [];
     $userGroups = [];
     if ($this->shareWithGroupOnly) {
         // Search in all the groups this user is part of
         $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
         foreach ($userGroups as $userGroup) {
             $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $this->limit, $this->offset);
             foreach ($usersTmp as $uid => $userDisplayName) {
                 $users[$uid] = $userDisplayName;
             }
         }
     } else {
         // Search in all users
         $usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset);
         foreach ($usersTmp as $user) {
             $users[$user->getUID()] = $user->getDisplayName();
         }
     }
     if (!$this->shareeEnumeration || sizeof($users) < $this->limit) {
         $this->reachedEndFor[] = 'users';
     }
     $foundUserById = false;
     foreach ($users as $uid => $userDisplayName) {
         if (strtolower($uid) === $search || strtolower($userDisplayName) === $search) {
             if (strtolower($uid) === $search) {
                 $foundUserById = true;
             }
             $this->result['exact']['users'][] = ['label' => $userDisplayName, 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $uid]];
         } else {
             $this->result['users'][] = ['label' => $userDisplayName, 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $uid]];
         }
     }
     if ($this->offset === 0 && !$foundUserById) {
         // On page one we try if the search result has a direct hit on the
         // user id and if so, we add that to the exact match list
         $user = $this->userManager->get($search);
         if ($user instanceof IUser) {
             $addUser = true;
             if ($this->shareWithGroupOnly) {
                 // Only add, if we have a common group
                 $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user));
                 $addUser = !empty($commonGroups);
             }
             if ($addUser) {
                 array_push($this->result['exact']['users'], ['label' => $user->getDisplayName(), 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $user->getUID()]]);
             }
         }
     }
     if (!$this->shareeEnumeration) {
         $this->result['users'] = [];
     }
 }
예제 #30
0
 /**
  * @param IUser|string $user
  * @return \OCA\Files_Sharing\Propagation\RecipientPropagator
  */
 public function getSharePropagator($user)
 {
     if (!$user instanceof IUser) {
         $user = $this->userManager->get($user);
     }
     if (isset($this->sharePropagators[$user->getUID()])) {
         return $this->sharePropagators[$user->getUID()];
     }
     $this->sharePropagators[$user->getUID()] = new RecipientPropagator($user, $this->getChangePropagator($user->getUID()), $this->config, $this, $this->groupManager);
     return $this->sharePropagators[$user->getUID()];
 }