2013-05-29 01:46:57 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2016-03-01 19:25:15 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Leon Klingele <leon@struktur.de>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
namespace OC\User;
|
|
|
|
|
2017-05-15 14:30:52 +03:00
|
|
|
use OC\Accounts\AccountManager;
|
2020-03-13 16:16:43 +03:00
|
|
|
use OC\Avatar\AvatarManager;
|
2016-08-11 10:52:02 +03:00
|
|
|
use OC\Files\Cache\Storage;
|
2013-05-29 01:46:57 +04:00
|
|
|
use OC\Hooks\Emitter;
|
2016-02-09 19:16:43 +03:00
|
|
|
use OC_Helper;
|
2015-11-25 23:44:36 +03:00
|
|
|
use OCP\IAvatarManager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IConfig;
|
2015-11-25 23:44:36 +03:00
|
|
|
use OCP\IImage;
|
2015-11-30 15:57:54 +03:00
|
|
|
use OCP\IURLGenerator;
|
2014-07-09 17:32:33 +04:00
|
|
|
use OCP\IUser;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IUserBackend;
|
2016-01-14 16:28:03 +03:00
|
|
|
use OCP\UserInterface;
|
2019-02-22 15:07:26 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2014-07-09 17:32:33 +04:00
|
|
|
class User implements IUser {
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var string */
|
2013-05-29 01:46:57 +04:00
|
|
|
private $uid;
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var string */
|
2013-05-29 01:46:57 +04:00
|
|
|
private $displayName;
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var UserInterface|null */
|
2013-05-29 01:46:57 +04:00
|
|
|
private $backend;
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var EventDispatcherInterface */
|
|
|
|
private $dispatcher;
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var bool */
|
2013-05-29 01:46:57 +04:00
|
|
|
private $enabled;
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var Emitter|Manager */
|
2013-05-29 01:46:57 +04:00
|
|
|
private $emitter;
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var string */
|
2013-12-11 19:22:26 +04:00
|
|
|
private $home;
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var int */
|
2014-05-21 20:03:37 +04:00
|
|
|
private $lastLogin;
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var \OCP\IConfig */
|
2013-12-16 17:22:25 +04:00
|
|
|
private $config;
|
|
|
|
|
2015-11-25 23:44:36 +03:00
|
|
|
/** @var IAvatarManager */
|
|
|
|
private $avatarManager;
|
|
|
|
|
2015-11-30 15:57:54 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
public function __construct(string $uid, ?UserInterface $backend, EventDispatcherInterface $dispatcher, $emitter = null, IConfig $config = null, $urlGenerator = null) {
|
2013-05-29 01:46:57 +04:00
|
|
|
$this->uid = $uid;
|
|
|
|
$this->backend = $backend;
|
2019-02-22 15:07:26 +03:00
|
|
|
$this->dispatcher = $dispatcher;
|
2013-05-29 01:46:57 +04:00
|
|
|
$this->emitter = $emitter;
|
2020-04-10 15:19:56 +03:00
|
|
|
if (is_null($config)) {
|
2016-01-21 18:19:53 +03:00
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
}
|
2013-12-16 17:22:25 +04:00
|
|
|
$this->config = $config;
|
2015-12-01 16:50:13 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2016-01-21 18:19:53 +03:00
|
|
|
$enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
|
|
|
|
$this->enabled = ($enabled === 'true');
|
|
|
|
$this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0);
|
2015-11-30 15:57:54 +03:00
|
|
|
if (is_null($this->urlGenerator)) {
|
|
|
|
$this->urlGenerator = \OC::$server->getURLGenerator();
|
|
|
|
}
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* get the user id
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUID() {
|
|
|
|
return $this->uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-02 16:25:07 +03:00
|
|
|
* get the display name for the user, if no specific display name is set it will fallback to the user id
|
2013-06-03 15:33:56 +04:00
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDisplayName() {
|
2014-02-22 01:53:31 +04:00
|
|
|
if (!isset($this->displayName)) {
|
2014-10-15 16:05:18 +04:00
|
|
|
$displayName = '';
|
2019-02-22 15:07:26 +03:00
|
|
|
if ($this->backend && $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) {
|
2014-10-15 16:05:18 +04:00
|
|
|
// get display name and strip whitespace from the beginning and end of it
|
|
|
|
$backendDisplayName = $this->backend->getDisplayName($this->uid);
|
|
|
|
if (is_string($backendDisplayName)) {
|
|
|
|
$displayName = trim($backendDisplayName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($displayName)) {
|
|
|
|
$this->displayName = $displayName;
|
2014-02-22 01:53:31 +04:00
|
|
|
} else {
|
|
|
|
$this->displayName = $this->uid;
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 01:46:57 +04:00
|
|
|
return $this->displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* set the displayname for the user
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @param string $displayName
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function setDisplayName($displayName) {
|
2014-10-15 16:05:18 +04:00
|
|
|
$displayName = trim($displayName);
|
2019-03-06 15:07:41 +03:00
|
|
|
$oldDisplayName = $this->getDisplayName();
|
2019-03-06 15:10:18 +03:00
|
|
|
if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName) && $displayName !== $oldDisplayName) {
|
2013-06-03 15:39:34 +04:00
|
|
|
$result = $this->backend->setDisplayName($this->uid, $displayName);
|
2016-01-18 23:01:16 +03:00
|
|
|
if ($result) {
|
|
|
|
$this->displayName = $displayName;
|
2019-03-06 15:07:41 +03:00
|
|
|
$this->triggerChange('displayName', $displayName, $oldDisplayName);
|
2016-01-18 23:01:16 +03:00
|
|
|
}
|
2013-06-03 15:39:34 +04:00
|
|
|
return $result !== false;
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
2019-04-11 10:49:21 +03:00
|
|
|
return false;
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
2016-01-18 22:27:43 +03:00
|
|
|
/**
|
|
|
|
* set the email address of the user
|
|
|
|
*
|
|
|
|
* @param string|null $mailAddress
|
|
|
|
* @return void
|
|
|
|
* @since 9.0.0
|
|
|
|
*/
|
|
|
|
public function setEMailAddress($mailAddress) {
|
2017-04-13 13:34:02 +03:00
|
|
|
$oldMailAddress = $this->getEMailAddress();
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($oldMailAddress !== $mailAddress) {
|
|
|
|
if ($mailAddress === '') {
|
2019-03-06 15:07:41 +03:00
|
|
|
$this->config->deleteUserValue($this->uid, 'settings', 'email');
|
|
|
|
} else {
|
|
|
|
$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
|
|
|
|
}
|
2017-06-01 12:23:46 +03:00
|
|
|
$this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
|
|
|
|
}
|
2016-01-18 22:27:43 +03:00
|
|
|
}
|
|
|
|
|
2014-05-21 20:03:37 +04:00
|
|
|
/**
|
|
|
|
* returns the timestamp of the user's last login or 0 if the user did never
|
|
|
|
* login
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getLastLogin() {
|
|
|
|
return $this->lastLogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* updates the timestamp of the most recent login of this user
|
|
|
|
*/
|
|
|
|
public function updateLastLoginTimestamp() {
|
2016-09-23 18:21:07 +03:00
|
|
|
$firstTimeLogin = ($this->lastLogin === 0);
|
2014-05-21 20:03:37 +04:00
|
|
|
$this->lastLogin = time();
|
2016-09-23 18:21:07 +03:00
|
|
|
$this->config->setUserValue(
|
2014-05-21 20:03:37 +04:00
|
|
|
$this->uid, 'login', 'lastLogin', $this->lastLogin);
|
2016-09-23 18:21:07 +03:00
|
|
|
|
|
|
|
return $firstTimeLogin;
|
2014-05-21 20:03:37 +04:00
|
|
|
}
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* Delete the user
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function delete() {
|
2019-02-22 15:07:26 +03:00
|
|
|
$this->dispatcher->dispatch(IUser::class . '::preDelete', new GenericEvent($this));
|
2013-05-29 01:46:57 +04:00
|
|
|
if ($this->emitter) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emitter->emit('\OC\User', 'preDelete', [$this]);
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
2016-12-20 18:12:51 +03:00
|
|
|
// get the home now because it won't return it after user deletion
|
|
|
|
$homePath = $this->getHome();
|
2013-05-29 01:46:57 +04:00
|
|
|
$result = $this->backend->deleteUser($this->uid);
|
2014-12-04 16:15:55 +03:00
|
|
|
if ($result) {
|
|
|
|
|
|
|
|
// FIXME: Feels like an hack - suggestions?
|
|
|
|
|
2017-03-03 10:24:27 +03:00
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
2014-12-04 16:15:55 +03:00
|
|
|
// We have to delete the user from all groups
|
2017-03-03 10:24:27 +03:00
|
|
|
foreach ($groupManager->getUserGroupIds($this) as $groupId) {
|
|
|
|
$group = $groupManager->get($groupId);
|
|
|
|
if ($group) {
|
|
|
|
\OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
|
|
|
|
$group->removeUser($this);
|
|
|
|
\OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
|
|
|
|
}
|
2014-12-04 16:15:55 +03:00
|
|
|
}
|
|
|
|
// Delete the user's keys in preferences
|
2014-12-04 18:48:07 +03:00
|
|
|
\OC::$server->getConfig()->deleteAllUserValues($this->uid);
|
2014-12-04 16:15:55 +03:00
|
|
|
|
|
|
|
// Delete user files in /data/
|
2016-12-20 18:12:51 +03:00
|
|
|
if ($homePath !== false) {
|
|
|
|
// FIXME: this operates directly on FS, should use View instead...
|
|
|
|
// also this is not testable/mockable...
|
|
|
|
\OC_Helper::rmdirr($homePath);
|
|
|
|
}
|
2014-12-04 16:15:55 +03:00
|
|
|
|
|
|
|
// Delete the users entry in the storage table
|
2016-08-11 10:52:02 +03:00
|
|
|
Storage::remove('home::' . $this->uid);
|
2015-12-03 18:35:57 +03:00
|
|
|
|
2016-02-03 21:28:15 +03:00
|
|
|
\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
|
2016-01-29 00:59:48 +03:00
|
|
|
\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
|
2016-09-28 14:59:50 +03:00
|
|
|
|
2020-03-13 16:16:43 +03:00
|
|
|
/** @var IAvatarManager $avatarManager */
|
|
|
|
$avatarManager = \OC::$server->query(AvatarManager::class);
|
|
|
|
$avatarManager->deleteUserAvatar($this->uid);
|
|
|
|
|
2016-09-28 14:59:50 +03:00
|
|
|
$notification = \OC::$server->getNotificationManager()->createNotification();
|
|
|
|
$notification->setUser($this->uid);
|
|
|
|
\OC::$server->getNotificationManager()->markProcessed($notification);
|
2014-12-04 16:15:55 +03:00
|
|
|
|
2017-05-15 14:30:52 +03:00
|
|
|
/** @var AccountManager $accountManager */
|
|
|
|
$accountManager = \OC::$server->query(AccountManager::class);
|
|
|
|
$accountManager->deleteUser($this);
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
$this->dispatcher->dispatch(IUser::class . '::postDelete', new GenericEvent($this));
|
2016-09-29 16:05:47 +03:00
|
|
|
if ($this->emitter) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emitter->emit('\OC\User', 'postDelete', [$this]);
|
2016-09-29 16:05:47 +03:00
|
|
|
}
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
return !($result === false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* Set the password of the user
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @param string $password
|
|
|
|
* @param string $recoveryPassword for the encryption app to reset encryption keys
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-07-24 14:50:39 +04:00
|
|
|
public function setPassword($password, $recoveryPassword = null) {
|
2019-02-22 15:07:26 +03:00
|
|
|
$this->dispatcher->dispatch(IUser::class . '::preSetPassword', new GenericEvent($this, [
|
|
|
|
'password' => $password,
|
|
|
|
'recoveryPassword' => $recoveryPassword,
|
|
|
|
]));
|
2013-06-06 15:30:18 +04:00
|
|
|
if ($this->emitter) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emitter->emit('\OC\User', 'preSetPassword', [$this, $password, $recoveryPassword]);
|
2013-06-06 15:30:18 +04:00
|
|
|
}
|
2016-08-11 10:52:02 +03:00
|
|
|
if ($this->backend->implementsActions(Backend::SET_PASSWORD)) {
|
2013-05-29 01:46:57 +04:00
|
|
|
$result = $this->backend->setPassword($this->uid, $password);
|
2019-02-22 15:07:26 +03:00
|
|
|
$this->dispatcher->dispatch(IUser::class . '::postSetPassword', new GenericEvent($this, [
|
|
|
|
'password' => $password,
|
|
|
|
'recoveryPassword' => $recoveryPassword,
|
|
|
|
]));
|
2013-05-29 01:46:57 +04:00
|
|
|
if ($this->emitter) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emitter->emit('\OC\User', 'postSetPassword', [$this, $password, $recoveryPassword]);
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
return !($result === false);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the users home folder to mount
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHome() {
|
2013-12-11 19:22:26 +04:00
|
|
|
if (!$this->home) {
|
2016-08-11 10:52:02 +03:00
|
|
|
if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
|
2013-12-11 19:22:26 +04:00
|
|
|
$this->home = $home;
|
2013-12-16 19:02:03 +04:00
|
|
|
} elseif ($this->config) {
|
2017-01-20 04:49:41 +03:00
|
|
|
$this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
|
2013-12-12 15:57:25 +04:00
|
|
|
} else {
|
2013-12-16 19:02:03 +04:00
|
|
|
$this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
|
2013-12-11 19:22:26 +04:00
|
|
|
}
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
2013-12-11 19:22:26 +04:00
|
|
|
return $this->home;
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
Expose backend type via REST API
This change will expose the user backend via the REST API which is a pre-requisite for https://github.com/owncloud/core/issues/12620.
For example:
````json
[{"name":"9707A09E-CA9A-4ABE-A66A-3F632F16C409","displayname":"Document Conversion User Account","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/9707A09E-CA9A-4ABE-A66A-3F632F16C409","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"ED86733E-745C-4E4D-90CB-278A9737DB3C","displayname":"Hacker","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/ED86733E-745C-4E4D-90CB-278A9737DB3C","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"71CDF45B-E125-450D-983C-D9192F36EC88","displayname":"admin","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/71CDF45B-E125-450D-983C-D9192F36EC88","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"admin","displayname":"admin","groups":["admin"],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/admin","lastLogin":"1418057287","backend":"OC_User_Database"},{"name":"test","displayname":"test","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/test","lastLogin":0,"backend":"OC_User_Database"}]
```
2014-12-09 00:38:54 +03:00
|
|
|
/**
|
|
|
|
* Get the name of the backend class the user is connected with
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getBackendClassName() {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($this->backend instanceof IUserBackend) {
|
2014-12-12 19:25:03 +03:00
|
|
|
return $this->backend->getBackendName();
|
|
|
|
}
|
Expose backend type via REST API
This change will expose the user backend via the REST API which is a pre-requisite for https://github.com/owncloud/core/issues/12620.
For example:
````json
[{"name":"9707A09E-CA9A-4ABE-A66A-3F632F16C409","displayname":"Document Conversion User Account","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/9707A09E-CA9A-4ABE-A66A-3F632F16C409","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"ED86733E-745C-4E4D-90CB-278A9737DB3C","displayname":"Hacker","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/ED86733E-745C-4E4D-90CB-278A9737DB3C","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"71CDF45B-E125-450D-983C-D9192F36EC88","displayname":"admin","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/71CDF45B-E125-450D-983C-D9192F36EC88","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"admin","displayname":"admin","groups":["admin"],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/admin","lastLogin":"1418057287","backend":"OC_User_Database"},{"name":"test","displayname":"test","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/test","lastLogin":0,"backend":"OC_User_Database"}]
```
2014-12-09 00:38:54 +03:00
|
|
|
return get_class($this->backend);
|
|
|
|
}
|
|
|
|
|
2018-10-11 22:55:42 +03:00
|
|
|
public function getBackend() {
|
|
|
|
return $this->backend;
|
|
|
|
}
|
|
|
|
|
2013-11-22 16:24:11 +04:00
|
|
|
/**
|
|
|
|
* check if the backend allows the user to change his avatar on Personal page
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canChangeAvatar() {
|
2016-08-11 10:52:02 +03:00
|
|
|
if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) {
|
2013-11-22 16:24:11 +04:00
|
|
|
return $this->backend->canChangeAvatar($this->uid);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* check if the backend supports changing passwords
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canChangePassword() {
|
2016-08-11 10:52:02 +03:00
|
|
|
return $this->backend->implementsActions(Backend::SET_PASSWORD);
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* check if the backend supports changing display names
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canChangeDisplayName() {
|
2016-01-21 18:19:53 +03:00
|
|
|
if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) {
|
2013-12-16 17:22:25 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-08-11 10:52:02 +03:00
|
|
|
return $this->backend->implementsActions(Backend::SET_DISPLAYNAME);
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* check if the user is enabled
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isEnabled() {
|
|
|
|
return $this->enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-03 15:33:56 +04:00
|
|
|
* set the enabled status for the user
|
|
|
|
*
|
2013-05-29 01:46:57 +04:00
|
|
|
* @param bool $enabled
|
|
|
|
*/
|
2018-04-06 21:19:52 +03:00
|
|
|
public function setEnabled(bool $enabled = true) {
|
2017-04-25 18:11:57 +03:00
|
|
|
$oldStatus = $this->isEnabled();
|
2013-05-29 01:46:57 +04:00
|
|
|
$this->enabled = $enabled;
|
2017-04-25 18:11:57 +03:00
|
|
|
if ($oldStatus !== $this->enabled) {
|
2019-04-11 10:49:21 +03:00
|
|
|
// TODO: First change the value, then trigger the event as done for all other properties.
|
|
|
|
$this->triggerChange('enabled', $enabled, $oldStatus);
|
2018-04-06 21:19:52 +03:00
|
|
|
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false');
|
2017-04-25 18:11:57 +03:00
|
|
|
}
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
2015-11-25 01:28:24 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get the users email address
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
* @since 9.0.0
|
|
|
|
*/
|
|
|
|
public function getEMailAddress() {
|
2015-12-01 14:05:40 +03:00
|
|
|
return $this->config->getUserValue($this->uid, 'settings', 'email', null);
|
2015-11-25 01:28:24 +03:00
|
|
|
}
|
2015-11-25 23:44:36 +03:00
|
|
|
|
2016-02-09 19:16:43 +03:00
|
|
|
/**
|
|
|
|
* get the users' quota
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @since 9.0.0
|
|
|
|
*/
|
|
|
|
public function getQuota() {
|
|
|
|
$quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($quota === 'default') {
|
2016-02-09 19:16:43 +03:00
|
|
|
$quota = $this->config->getAppValue('files', 'default_quota', 'none');
|
|
|
|
}
|
|
|
|
return $quota;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the users' quota
|
|
|
|
*
|
|
|
|
* @param string $quota
|
|
|
|
* @return void
|
|
|
|
* @since 9.0.0
|
|
|
|
*/
|
|
|
|
public function setQuota($quota) {
|
2017-06-01 12:23:46 +03:00
|
|
|
$oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($quota !== 'none' and $quota !== 'default') {
|
2016-02-09 19:41:04 +03:00
|
|
|
$quota = OC_Helper::computerFileSize($quota);
|
|
|
|
$quota = OC_Helper::humanFileSize($quota);
|
2016-02-09 19:16:43 +03:00
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($quota !== $oldQuota) {
|
2019-03-06 15:07:41 +03:00
|
|
|
$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
|
2019-04-11 10:49:21 +03:00
|
|
|
$this->triggerChange('quota', $quota, $oldQuota);
|
2017-06-01 12:23:46 +03:00
|
|
|
}
|
2016-02-09 19:16:43 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 23:44:36 +03:00
|
|
|
/**
|
|
|
|
* get the avatar image if it exists
|
|
|
|
*
|
|
|
|
* @param int $size
|
|
|
|
* @return IImage|null
|
|
|
|
* @since 9.0.0
|
|
|
|
*/
|
|
|
|
public function getAvatarImage($size) {
|
2015-12-02 16:25:07 +03:00
|
|
|
// delay the initialization
|
|
|
|
if (is_null($this->avatarManager)) {
|
|
|
|
$this->avatarManager = \OC::$server->getAvatarManager();
|
|
|
|
}
|
|
|
|
|
2015-11-25 23:44:36 +03:00
|
|
|
$avatar = $this->avatarManager->getAvatar($this->uid);
|
|
|
|
$image = $avatar->get(-1);
|
|
|
|
if ($image) {
|
|
|
|
return $image;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2015-11-30 15:57:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get the federation cloud id
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @since 9.0.0
|
|
|
|
*/
|
|
|
|
public function getCloudId() {
|
|
|
|
$uid = $this->getUID();
|
|
|
|
$server = $this->urlGenerator->getAbsoluteURL('/');
|
2020-04-09 17:07:47 +03:00
|
|
|
$server = rtrim($this->removeProtocolFromUrl($server), '/');
|
2017-01-27 14:52:17 +03:00
|
|
|
return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId();
|
2015-11-30 15:57:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $url
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function removeProtocolFromUrl($url) {
|
|
|
|
if (strpos($url, 'https://') === 0) {
|
|
|
|
return substr($url, strlen('https://'));
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif (strpos($url, 'http://') === 0) {
|
2015-11-30 15:57:54 +03:00
|
|
|
return substr($url, strlen('http://'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
2016-01-18 22:27:43 +03:00
|
|
|
|
2017-04-13 13:34:02 +03:00
|
|
|
public function triggerChange($feature, $value = null, $oldValue = null) {
|
2019-02-22 15:07:26 +03:00
|
|
|
$this->dispatcher->dispatch(IUser::class . '::changeUser', new GenericEvent($this, [
|
|
|
|
'feature' => $feature,
|
|
|
|
'value' => $value,
|
|
|
|
'oldValue' => $oldValue,
|
|
|
|
]));
|
2016-01-22 13:34:49 +03:00
|
|
|
if ($this->emitter) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emitter->emit('\OC\User', 'changeUser', [$this, $feature, $value, $oldValue]);
|
2016-01-22 13:34:49 +03:00
|
|
|
}
|
|
|
|
}
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|