/**
  * Move files from User before account deletion
  * @param \OC\User\User $user
  */
 public function saveUserFiles(\OC\User\User $user)
 {
     // mv the files (<datadir>/uid)
     // TODO: quid du cas où un gros fichier est en train d'être uploadé / downloadé au moment du move ?
     if ($this->isUserBackupEnabled()) {
         // user ID (and name of user dir on owncloud)
         $uid = $user->getUID();
         // backup dir to store user's files before user deletion
         $userBackupDir = $this->getUserBackupDir();
         if (!file_exists($userBackupDir)) {
             mkdir($userBackupDir, 0700, true);
         }
         // owncloud data dir
         $OCDataDir = $this->getOCDataDir();
         $moveFrom = $OCDataDir . '/' . $uid;
         $moveTo = $userBackupDir . '/' . $uid . date('Ymd_His');
         if (file_exists($moveFrom) and !file_exists($moveTo)) {
             // $this->logger->info("Files backup before deletion for user $uid is done into $moveTo", array('app' => $this->appName));
             \OCP\Util::writeLog($this->appName, "Files backup before deletion for user {$uid} is done into {$moveTo}", \OCP\Util::INFO);
             rename($moveFrom, $moveTo);
         }
         // then re-create the 'uid' dir to no interfere with normal deletion process
         if (!file_exists($moveFrom)) {
             mkdir($moveFrom);
         }
     } else {
         $this->logger->error("Files backup before deletion has failed for user {$uid}", array('app' => $this->appName));
     }
 }
Exemple #2
0
 /**
  * Construct a Home storage instance
  * @param array $arguments array with "user" containing the
  * storage owner and "legacy" containing "true" if the storage is
  * a legacy storage with "local::" URL instead of the new "home::" one.
  */
 public function __construct($arguments)
 {
     $this->user = $arguments['user'];
     $datadir = $this->user->getHome();
     if (isset($arguments['legacy']) && $arguments['legacy']) {
         // legacy home id (<= 5.0.12)
         $this->id = 'local::' . $datadir . '/';
     } else {
         $this->id = 'home::' . $this->user->getUID();
     }
     parent::__construct(array('datadir' => $datadir));
 }
Exemple #3
0
 /**
  * @param IToken $dbToken
  * @param string $token
  * @return boolean
  */
 private function checkTokenCredentials(IToken $dbToken, $token)
 {
     // Check whether login credentials are still valid and the user was not disabled
     // This check is performed each 5 minutes
     $lastCheck = $dbToken->getLastCheck() ?: 0;
     $now = $this->timeFacory->getTime();
     if ($lastCheck > $now - 60 * 5) {
         // Checked performed recently, nothing to do now
         return true;
     }
     try {
         $pwd = $this->tokenProvider->getPassword($dbToken, $token);
     } catch (InvalidTokenException $ex) {
         // An invalid token password was used -> log user out
         return false;
     } catch (PasswordlessTokenException $ex) {
         // Token has no password
         if (!is_null($this->activeUser) && !$this->activeUser->isEnabled()) {
             $this->tokenProvider->invalidateToken($token);
             return false;
         }
         $dbToken->setLastCheck($now);
         $this->tokenProvider->updateToken($dbToken);
         return true;
     }
     if ($this->manager->checkPassword($dbToken->getLoginName(), $pwd) === false || !is_null($this->activeUser) && !$this->activeUser->isEnabled()) {
         $this->tokenProvider->invalidateToken($token);
         // Password has changed or user was disabled -> log user out
         return false;
     }
     $dbToken->setLastCheck($now);
     $this->tokenProvider->updateToken($dbToken);
     return true;
 }
Exemple #4
0
 protected function setUp()
 {
     parent::setUp();
     $manager = \OC\Files\Filesystem::getMountManager();
     \OC_Hook::clear('OC_Filesystem');
     $user = new User($this->getUniqueID('user'), new \Test\Util\User\Dummy());
     $this->loginAsUser($user->getUID());
     $this->view = new View();
     $this->root = new Root($manager, $this->view, $user);
     $storage = new Temporary(array());
     $subStorage = new Temporary(array());
     $this->storages[] = $storage;
     $this->storages[] = $subStorage;
     $this->root->mount($storage, '/');
     $this->root->mount($subStorage, '/substorage/');
 }
Exemple #5
0
 /**
  * @inheritdoc
  */
 public function getFile($size)
 {
     $ext = $this->getExtension();
     if ($size === -1) {
         $path = 'avatar.' . $ext;
     } else {
         $path = 'avatar.' . $size . '.' . $ext;
     }
     try {
         $file = $this->folder->get($path);
     } catch (NotFoundException $e) {
         if ($size <= 0) {
             throw new NotFoundException();
         }
         $avatar = new OC_Image();
         /** @var File $file */
         $file = $this->folder->get('avatar.' . $ext);
         $avatar->loadFromData($file->getContent());
         if ($size !== -1) {
             $avatar->resize($size);
         }
         try {
             $file = $this->folder->newFile($path);
             $file->putContent($avatar->data());
         } catch (NotPermittedException $e) {
             $this->logger->error('Failed to save avatar for ' . $this->user->getUID());
         }
     }
     return $file;
 }
Exemple #6
0
 /**
  * remove the users avatar
  * @return void
  */
 public function remove()
 {
     $regex = '/^avatar\\.([0-9]+\\.)?(jpg|png)$/';
     $avatars = $this->folder->search('avatar');
     foreach ($avatars as $avatar) {
         if (preg_match($regex, $avatar->getName())) {
             $avatar->delete();
         }
     }
     $this->user->triggerChange();
 }
 protected function setUp()
 {
     parent::setUp();
     $manager = \OC\Files\Filesystem::getMountManager();
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Updater', 'writeHook');
     \OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Updater', 'deleteHook');
     \OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Updater', 'renameHook');
     \OC_Hook::connect('OC_Filesystem', 'post_touch', '\\OC\\Files\\Cache\\Updater', 'touchHook');
     $user = new User($this->getUniqueID('user'), new \OC_User_Dummy());
     $this->loginAsUser($user->getUID());
     $this->view = new View();
     $this->root = new Root($manager, $this->view, $user);
     $storage = new Temporary(array());
     $subStorage = new Temporary(array());
     $this->storages[] = $storage;
     $this->storages[] = $subStorage;
     $this->root->mount($storage, '/');
     $this->root->mount($subStorage, '/substorage/');
 }
 /**
  * Send a mail signaling a user deletion
  * @param \OC\User\User $user
  */
 public function mailUserDeletion(\OC\User\User $user)
 {
     $toAddress = $toName = $this->config->getSystemValue('monitoring_admin_email');
     $theme = new \OC_Defaults();
     $now = new \DateTime();
     $niceNow = date_format($now, 'd/m/Y H:i:s');
     $subject = (string) $this->l->t('%s - User %s just has been deleted (%s)', array($theme->getTitle(), $user->getUID(), $niceNow));
     $html = new \OCP\Template($this->appName, "mail_userdeletion_html", "");
     $html->assign('userUID', $user->getUID());
     $html->assign('datetime', $niceNow);
     $htmlMail = $html->fetchPage();
     $alttext = new \OCP\Template($this->appName, "mail_userdeletion_text", "");
     $alttext->assign('userUID', $user->getUID());
     $alttext->assign('datetime', $niceNow);
     $altMail = $alttext->fetchPage();
     $fromAddress = $fromName = \OCP\Util::getDefaultEmailAddress('owncloud');
     try {
         \OCP\Util::sendMail($toAddress, $toName, $subject, $htmlMail, $fromAddress, $fromName, 1, $altMail);
     } catch (\Exception $e) {
         \OCP\Util::writeLog('user_account_actions', "Can't send mail for user deletion: " . $e->getMessage(), \OCP\Util::ERROR);
     }
 }
Exemple #9
0
 /**
  * remove a user from the group
  *
  * @param \OC\User\User $user
  */
 public function removeUser($user)
 {
     $result = false;
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\Group', 'preRemoveUser', array($this, $user));
     }
     foreach ($this->backends as $backend) {
         if ($backend->implementsActions(\OC_Group_Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
             $backend->removeFromGroup($user->getUID(), $this->gid);
             $result = true;
         }
     }
     if ($result) {
         if ($this->emitter) {
             $this->emitter->emit('\\OC\\Group', 'postRemoveUser', array($this, $user));
         }
         if ($this->users) {
             foreach ($this->users as $index => $groupUser) {
                 if ($groupUser->getUID() === $user->getUID()) {
                     unset($this->users[$index]);
                     return;
                 }
             }
         }
     }
 }
Exemple #10
0
	/**
	 * copies the skeleton to the users /files
	 *
	 * @param \OC\User\User $user
	 * @param \OCP\Files\Folder $userDirectory
	 */
	public static function copySkeleton(\OC\User\User $user, \OCP\Files\Folder $userDirectory) {

		$skeletonDirectory = \OCP\Config::getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');

		if (!empty($skeletonDirectory)) {
			\OCP\Util::writeLog(
				'files_skeleton',
				'copying skeleton for '.$user->getUID().' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
				\OCP\Util::DEBUG
			);
			self::copyr($skeletonDirectory, $userDirectory);
			// update the file cache
			$userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
		}
	}
 /**
  * @param \OC\User\User $user
  * @return \OC\Group\Group[]
  */
 public function getUserGroups($user)
 {
     $groups = array();
     foreach ($this->backends as $backend) {
         $groupIds = $backend->getUserGroups($user->getUID());
         foreach ($groupIds as $groupId) {
             $groups[$groupId] = $this->getGroupObject($groupId);
         }
     }
     return array_values($groups);
 }
Exemple #12
0
 /**
  * @param \OC\User\User $user
  * @return \OC\Group\Group[]
  */
 public function getUserGroups($user)
 {
     return $this->getUserIdGroups($user->getUID());
 }
Exemple #13
0
 /**
  * Delete all SAML identities associated with a user
  *
  * @param \OC\User\User $user user which has been deleted
  */
 private function onPostDelete($user)
 {
     $ids = $this->identityMapper->getAllIdentities($user->getUID());
     foreach ($ids as &$identity) {
         // TODO: When automated identity consolidation is
         // finally implemented, uncomment this line
         // $this->identityMapper->removeIdenity($identity);
     }
 }
 function testGetCertificateBundle()
 {
     $this->assertSame($this->user->getHome() . '/files_external/rootcerts.crt', $this->certificateManager->getCertificateBundle());
 }
Exemple #15
0
 /**
  * get the owner of a path
  *
  * @param string $path The path to get the owner
  * @return string uid or false
  */
 public function getOwner($path)
 {
     return $this->user->getUID();
 }
 /**
  * get a list of group ids for a user
  * @param \OC\User\User $user
  * @return array with group ids
  */
 public function getUserGroupIds($user)
 {
     $groupIds = array();
     $userId = $user->getUID();
     if (isset($this->cachedUserGroups[$userId])) {
         return array_keys($this->cachedUserGroups[$userId]);
     } else {
         foreach ($this->backends as $backend) {
             $groupIds = array_merge($groupIds, $backend->getUserGroups($userId));
         }
     }
     return $groupIds;
 }
Exemple #17
0
 /**
  * @param \OC\User\User $user
  * @return array with group names
  */
 public function getUserGroupIds($user)
 {
     $groupIds = array();
     foreach ($this->backends as $backend) {
         $groupIds = array_merge($groupIds, $backend->getUserGroups($user->getUID()));
     }
     return $groupIds;
 }