User.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\User;
  8. use InvalidArgumentException;
  9. use OC\Accounts\AccountManager;
  10. use OC\Avatar\AvatarManager;
  11. use OC\Hooks\Emitter;
  12. use OC_Helper;
  13. use OCP\Accounts\IAccountManager;
  14. use OCP\Comments\ICommentsManager;
  15. use OCP\EventDispatcher\IEventDispatcher;
  16. use OCP\Group\Events\BeforeUserRemovedEvent;
  17. use OCP\Group\Events\UserRemovedEvent;
  18. use OCP\IAvatarManager;
  19. use OCP\IConfig;
  20. use OCP\IDBConnection;
  21. use OCP\IGroupManager;
  22. use OCP\IImage;
  23. use OCP\IURLGenerator;
  24. use OCP\IUser;
  25. use OCP\IUserBackend;
  26. use OCP\Notification\IManager as INotificationManager;
  27. use OCP\User\Backend\IGetHomeBackend;
  28. use OCP\User\Backend\IPasswordHashBackend;
  29. use OCP\User\Backend\IProvideAvatarBackend;
  30. use OCP\User\Backend\IProvideEnabledStateBackend;
  31. use OCP\User\Backend\ISetDisplayNameBackend;
  32. use OCP\User\Backend\ISetPasswordBackend;
  33. use OCP\User\Events\BeforePasswordUpdatedEvent;
  34. use OCP\User\Events\BeforeUserDeletedEvent;
  35. use OCP\User\Events\PasswordUpdatedEvent;
  36. use OCP\User\Events\UserChangedEvent;
  37. use OCP\User\Events\UserDeletedEvent;
  38. use OCP\User\GetQuotaEvent;
  39. use OCP\UserInterface;
  40. use Psr\Log\LoggerInterface;
  41. use function json_decode;
  42. use function json_encode;
  43. class User implements IUser {
  44. private const CONFIG_KEY_MANAGERS = 'manager';
  45. private IConfig $config;
  46. private IURLGenerator $urlGenerator;
  47. /** @var IAccountManager */
  48. protected $accountManager;
  49. /** @var string|null */
  50. private $displayName;
  51. /** @var bool|null */
  52. private $enabled;
  53. /** @var Emitter|Manager|null */
  54. private $emitter;
  55. /** @var string */
  56. private $home;
  57. private ?int $lastLogin = null;
  58. private ?int $firstLogin = null;
  59. /** @var IAvatarManager */
  60. private $avatarManager;
  61. public function __construct(
  62. private string $uid,
  63. private ?UserInterface $backend,
  64. private IEventDispatcher $dispatcher,
  65. $emitter = null,
  66. ?IConfig $config = null,
  67. $urlGenerator = null,
  68. ) {
  69. $this->emitter = $emitter;
  70. $this->config = $config ?? \OCP\Server::get(IConfig::class);
  71. $this->urlGenerator = $urlGenerator ?? \OCP\Server::get(IURLGenerator::class);
  72. }
  73. /**
  74. * get the user id
  75. *
  76. * @return string
  77. */
  78. public function getUID() {
  79. return $this->uid;
  80. }
  81. /**
  82. * get the display name for the user, if no specific display name is set it will fallback to the user id
  83. *
  84. * @return string
  85. */
  86. public function getDisplayName() {
  87. if ($this->displayName === null) {
  88. $displayName = '';
  89. if ($this->backend && $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) {
  90. // get display name and strip whitespace from the beginning and end of it
  91. $backendDisplayName = $this->backend->getDisplayName($this->uid);
  92. if (is_string($backendDisplayName)) {
  93. $displayName = trim($backendDisplayName);
  94. }
  95. }
  96. if (!empty($displayName)) {
  97. $this->displayName = $displayName;
  98. } else {
  99. $this->displayName = $this->uid;
  100. }
  101. }
  102. return $this->displayName;
  103. }
  104. /**
  105. * set the displayname for the user
  106. *
  107. * @param string $displayName
  108. * @return bool
  109. *
  110. * @since 25.0.0 Throw InvalidArgumentException
  111. * @throws \InvalidArgumentException
  112. */
  113. public function setDisplayName($displayName) {
  114. $displayName = trim($displayName);
  115. $oldDisplayName = $this->getDisplayName();
  116. if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName) && $displayName !== $oldDisplayName) {
  117. /** @var ISetDisplayNameBackend $backend */
  118. $backend = $this->backend;
  119. $result = $backend->setDisplayName($this->uid, $displayName);
  120. if ($result) {
  121. $this->displayName = $displayName;
  122. $this->triggerChange('displayName', $displayName, $oldDisplayName);
  123. }
  124. return $result !== false;
  125. }
  126. return false;
  127. }
  128. /**
  129. * @inheritDoc
  130. */
  131. public function setEMailAddress($mailAddress) {
  132. $this->setSystemEMailAddress($mailAddress);
  133. }
  134. /**
  135. * @inheritDoc
  136. */
  137. public function setSystemEMailAddress(string $mailAddress): void {
  138. $oldMailAddress = $this->getSystemEMailAddress();
  139. if ($mailAddress === '') {
  140. $this->config->deleteUserValue($this->uid, 'settings', 'email');
  141. } else {
  142. $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
  143. }
  144. $primaryAddress = $this->getPrimaryEMailAddress();
  145. if ($primaryAddress === $mailAddress) {
  146. // on match no dedicated primary settings is necessary
  147. $this->setPrimaryEMailAddress('');
  148. }
  149. if ($oldMailAddress !== strtolower($mailAddress)) {
  150. $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
  151. }
  152. }
  153. /**
  154. * @inheritDoc
  155. */
  156. public function setPrimaryEMailAddress(string $mailAddress): void {
  157. if ($mailAddress === '') {
  158. $this->config->deleteUserValue($this->uid, 'settings', 'primary_email');
  159. return;
  160. }
  161. $this->ensureAccountManager();
  162. $account = $this->accountManager->getAccount($this);
  163. $property = $account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)
  164. ->getPropertyByValue($mailAddress);
  165. if ($property === null || $property->getLocallyVerified() !== IAccountManager::VERIFIED) {
  166. throw new InvalidArgumentException('Only verified emails can be set as primary');
  167. }
  168. $this->config->setUserValue($this->uid, 'settings', 'primary_email', $mailAddress);
  169. }
  170. private function ensureAccountManager() {
  171. if (!$this->accountManager instanceof IAccountManager) {
  172. $this->accountManager = \OC::$server->get(IAccountManager::class);
  173. }
  174. }
  175. /**
  176. * returns the timestamp of the user's last login or 0 if the user did never
  177. * login
  178. */
  179. public function getLastLogin(): int {
  180. if ($this->lastLogin === null) {
  181. $this->lastLogin = (int)$this->config->getUserValue($this->uid, 'login', 'lastLogin', 0);
  182. }
  183. return $this->lastLogin;
  184. }
  185. /**
  186. * returns the timestamp of the user's last login or 0 if the user did never
  187. * login
  188. */
  189. public function getFirstLogin(): int {
  190. if ($this->firstLogin === null) {
  191. $this->firstLogin = (int)$this->config->getUserValue($this->uid, 'login', 'firstLogin', 0);
  192. }
  193. return $this->firstLogin;
  194. }
  195. /**
  196. * updates the timestamp of the most recent login of this user
  197. */
  198. public function updateLastLoginTimestamp(): bool {
  199. $previousLogin = $this->getLastLogin();
  200. $firstLogin = $this->getFirstLogin();
  201. $now = time();
  202. $firstTimeLogin = $previousLogin === 0;
  203. if ($now - $previousLogin > 60) {
  204. $this->lastLogin = $now;
  205. $this->config->setUserValue($this->uid, 'login', 'lastLogin', (string)$this->lastLogin);
  206. }
  207. if ($firstLogin === 0) {
  208. if ($firstTimeLogin) {
  209. $this->firstLogin = $now;
  210. } else {
  211. /* Unknown first login, most likely was before upgrade to Nextcloud 31 */
  212. $this->firstLogin = -1;
  213. }
  214. $this->config->setUserValue($this->uid, 'login', 'firstLogin', (string)$this->firstLogin);
  215. }
  216. return $firstTimeLogin;
  217. }
  218. /**
  219. * Delete the user
  220. *
  221. * @return bool
  222. */
  223. public function delete() {
  224. if ($this->backend === null) {
  225. \OCP\Server::get(LoggerInterface::class)->error('Cannot delete user: No backend set');
  226. return false;
  227. }
  228. if ($this->emitter) {
  229. /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
  230. $this->emitter->emit('\OC\User', 'preDelete', [$this]);
  231. }
  232. $this->dispatcher->dispatchTyped(new BeforeUserDeletedEvent($this));
  233. // Set delete flag on the user - this is needed to ensure that the user data is removed if there happen any exception in the backend
  234. // because we can not restore the user meaning we could not rollback to any stable state otherwise.
  235. $this->config->setUserValue($this->uid, 'core', 'deleted', 'true');
  236. // We also need to backup the home path as this can not be reconstructed later if the original backend uses custom home paths
  237. $this->config->setUserValue($this->uid, 'core', 'deleted.home-path', $this->getHome());
  238. // Try to delete the user on the backend
  239. $result = $this->backend->deleteUser($this->uid);
  240. if ($result === false) {
  241. // The deletion was aborted or something else happened, we are in a defined state, so remove the delete flag
  242. $this->config->deleteUserValue($this->uid, 'core', 'deleted');
  243. return false;
  244. }
  245. // We have to delete the user from all groups
  246. $groupManager = \OCP\Server::get(IGroupManager::class);
  247. foreach ($groupManager->getUserGroupIds($this) as $groupId) {
  248. $group = $groupManager->get($groupId);
  249. if ($group) {
  250. $this->dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $this));
  251. $group->removeUser($this);
  252. $this->dispatcher->dispatchTyped(new UserRemovedEvent($group, $this));
  253. }
  254. }
  255. $commentsManager = \OCP\Server::get(ICommentsManager::class);
  256. $commentsManager->deleteReferencesOfActor('users', $this->uid);
  257. $commentsManager->deleteReadMarksFromUser($this);
  258. $avatarManager = \OCP\Server::get(AvatarManager::class);
  259. $avatarManager->deleteUserAvatar($this->uid);
  260. $notificationManager = \OCP\Server::get(INotificationManager::class);
  261. $notification = $notificationManager->createNotification();
  262. $notification->setUser($this->uid);
  263. $notificationManager->markProcessed($notification);
  264. $accountManager = \OCP\Server::get(AccountManager::class);
  265. $accountManager->deleteUser($this);
  266. $database = \OCP\Server::get(IDBConnection::class);
  267. try {
  268. // We need to create a transaction to make sure we are in a defined state
  269. // because if all user values are removed also the flag is gone, but if an exception happens (e.g. database lost connection on the set operation)
  270. // exactly here we are in an undefined state as the data is still present but the user does not exist on the system anymore.
  271. $database->beginTransaction();
  272. // Remove all user settings
  273. $this->config->deleteAllUserValues($this->uid);
  274. // But again set flag that this user is about to be deleted
  275. $this->config->setUserValue($this->uid, 'core', 'deleted', 'true');
  276. $this->config->setUserValue($this->uid, 'core', 'deleted.home-path', $this->getHome());
  277. // Commit the transaction so we are in a defined state: either the preferences are removed or an exception occurred but the delete flag is still present
  278. $database->commit();
  279. } catch (\Throwable $e) {
  280. $database->rollback();
  281. throw $e;
  282. }
  283. if ($this->emitter !== null) {
  284. /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
  285. $this->emitter->emit('\OC\User', 'postDelete', [$this]);
  286. }
  287. $this->dispatcher->dispatchTyped(new UserDeletedEvent($this));
  288. // Finally we can unset the delete flag and all other states
  289. $this->config->deleteAllUserValues($this->uid);
  290. return true;
  291. }
  292. /**
  293. * Set the password of the user
  294. *
  295. * @param string $password
  296. * @param string $recoveryPassword for the encryption app to reset encryption keys
  297. * @return bool
  298. */
  299. public function setPassword($password, $recoveryPassword = null) {
  300. $this->dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($this, $password, $recoveryPassword));
  301. if ($this->emitter) {
  302. $this->emitter->emit('\OC\User', 'preSetPassword', [$this, $password, $recoveryPassword]);
  303. }
  304. if ($this->backend->implementsActions(Backend::SET_PASSWORD)) {
  305. /** @var ISetPasswordBackend $backend */
  306. $backend = $this->backend;
  307. $result = $backend->setPassword($this->uid, $password);
  308. if ($result !== false) {
  309. $this->dispatcher->dispatchTyped(new PasswordUpdatedEvent($this, $password, $recoveryPassword));
  310. if ($this->emitter) {
  311. $this->emitter->emit('\OC\User', 'postSetPassword', [$this, $password, $recoveryPassword]);
  312. }
  313. }
  314. return !($result === false);
  315. } else {
  316. return false;
  317. }
  318. }
  319. public function getPasswordHash(): ?string {
  320. if (!($this->backend instanceof IPasswordHashBackend)) {
  321. return null;
  322. }
  323. return $this->backend->getPasswordHash($this->uid);
  324. }
  325. public function setPasswordHash(string $passwordHash): bool {
  326. if (!($this->backend instanceof IPasswordHashBackend)) {
  327. return false;
  328. }
  329. return $this->backend->setPasswordHash($this->uid, $passwordHash);
  330. }
  331. /**
  332. * get the users home folder to mount
  333. *
  334. * @return string
  335. */
  336. public function getHome() {
  337. if (!$this->home) {
  338. /** @psalm-suppress UndefinedInterfaceMethod Once we get rid of the legacy implementsActions, psalm won't complain anymore */
  339. if (($this->backend instanceof IGetHomeBackend || $this->backend->implementsActions(Backend::GET_HOME)) && $home = $this->backend->getHome($this->uid)) {
  340. $this->home = $home;
  341. } else {
  342. $this->home = $this->config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
  343. }
  344. }
  345. return $this->home;
  346. }
  347. /**
  348. * Get the name of the backend class the user is connected with
  349. *
  350. * @return string
  351. */
  352. public function getBackendClassName() {
  353. if ($this->backend instanceof IUserBackend) {
  354. return $this->backend->getBackendName();
  355. }
  356. return get_class($this->backend);
  357. }
  358. public function getBackend(): ?UserInterface {
  359. return $this->backend;
  360. }
  361. /**
  362. * Check if the backend allows the user to change their avatar on Personal page
  363. *
  364. * @return bool
  365. */
  366. public function canChangeAvatar() {
  367. if ($this->backend instanceof IProvideAvatarBackend || $this->backend->implementsActions(Backend::PROVIDE_AVATAR)) {
  368. /** @var IProvideAvatarBackend $backend */
  369. $backend = $this->backend;
  370. return $backend->canChangeAvatar($this->uid);
  371. }
  372. return true;
  373. }
  374. /**
  375. * check if the backend supports changing passwords
  376. *
  377. * @return bool
  378. */
  379. public function canChangePassword() {
  380. return $this->backend->implementsActions(Backend::SET_PASSWORD);
  381. }
  382. /**
  383. * check if the backend supports changing display names
  384. *
  385. * @return bool
  386. */
  387. public function canChangeDisplayName() {
  388. if (!$this->config->getSystemValueBool('allow_user_to_change_display_name', true)) {
  389. return false;
  390. }
  391. return $this->backend->implementsActions(Backend::SET_DISPLAYNAME);
  392. }
  393. /**
  394. * check if the user is enabled
  395. *
  396. * @return bool
  397. */
  398. public function isEnabled() {
  399. $queryDatabaseValue = function (): bool {
  400. if ($this->enabled === null) {
  401. $enabled = $this->config->getUserValue($this->uid, 'core', 'enabled', 'true');
  402. $this->enabled = $enabled === 'true';
  403. }
  404. return $this->enabled;
  405. };
  406. if ($this->backend instanceof IProvideEnabledStateBackend) {
  407. return $this->backend->isUserEnabled($this->uid, $queryDatabaseValue);
  408. } else {
  409. return $queryDatabaseValue();
  410. }
  411. }
  412. /**
  413. * set the enabled status for the user
  414. *
  415. * @return void
  416. */
  417. public function setEnabled(bool $enabled = true) {
  418. $oldStatus = $this->isEnabled();
  419. $setDatabaseValue = function (bool $enabled): void {
  420. $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false');
  421. $this->enabled = $enabled;
  422. };
  423. if ($this->backend instanceof IProvideEnabledStateBackend) {
  424. $queryDatabaseValue = function (): bool {
  425. if ($this->enabled === null) {
  426. $enabled = $this->config->getUserValue($this->uid, 'core', 'enabled', 'true');
  427. $this->enabled = $enabled === 'true';
  428. }
  429. return $this->enabled;
  430. };
  431. $enabled = $this->backend->setUserEnabled($this->uid, $enabled, $queryDatabaseValue, $setDatabaseValue);
  432. if ($oldStatus !== $enabled) {
  433. $this->triggerChange('enabled', $enabled, $oldStatus);
  434. }
  435. } elseif ($oldStatus !== $enabled) {
  436. $setDatabaseValue($enabled);
  437. $this->triggerChange('enabled', $enabled, $oldStatus);
  438. }
  439. }
  440. /**
  441. * get the users email address
  442. *
  443. * @return string|null
  444. * @since 9.0.0
  445. */
  446. public function getEMailAddress() {
  447. return $this->getPrimaryEMailAddress() ?? $this->getSystemEMailAddress();
  448. }
  449. /**
  450. * @inheritDoc
  451. */
  452. public function getSystemEMailAddress(): ?string {
  453. return $this->config->getUserValue($this->uid, 'settings', 'email', null);
  454. }
  455. /**
  456. * @inheritDoc
  457. */
  458. public function getPrimaryEMailAddress(): ?string {
  459. return $this->config->getUserValue($this->uid, 'settings', 'primary_email', null);
  460. }
  461. /**
  462. * get the users' quota
  463. *
  464. * @return string
  465. * @since 9.0.0
  466. */
  467. public function getQuota() {
  468. // allow apps to modify the user quota by hooking into the event
  469. $event = new GetQuotaEvent($this);
  470. $this->dispatcher->dispatchTyped($event);
  471. $overwriteQuota = $event->getQuota();
  472. if ($overwriteQuota) {
  473. $quota = $overwriteQuota;
  474. } else {
  475. $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
  476. }
  477. if ($quota === 'default') {
  478. $quota = $this->config->getAppValue('files', 'default_quota', 'none');
  479. // if unlimited quota is not allowed => avoid getting 'unlimited' as default_quota fallback value
  480. // use the first preset instead
  481. $allowUnlimitedQuota = $this->config->getAppValue('files', 'allow_unlimited_quota', '1') === '1';
  482. if (!$allowUnlimitedQuota) {
  483. $presets = $this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
  484. $presets = array_filter(array_map('trim', explode(',', $presets)));
  485. $quotaPreset = array_values(array_diff($presets, ['default', 'none']));
  486. if (count($quotaPreset) > 0) {
  487. $quota = $this->config->getAppValue('files', 'default_quota', $quotaPreset[0]);
  488. }
  489. }
  490. }
  491. return $quota;
  492. }
  493. /**
  494. * set the users' quota
  495. *
  496. * @param string $quota
  497. * @return void
  498. * @throws InvalidArgumentException
  499. * @since 9.0.0
  500. */
  501. public function setQuota($quota) {
  502. $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
  503. if ($quota !== 'none' and $quota !== 'default') {
  504. $bytesQuota = OC_Helper::computerFileSize($quota);
  505. if ($bytesQuota === false) {
  506. throw new InvalidArgumentException('Failed to set quota to invalid value ' . $quota);
  507. }
  508. $quota = OC_Helper::humanFileSize($bytesQuota);
  509. }
  510. if ($quota !== $oldQuota) {
  511. $this->config->setUserValue($this->uid, 'files', 'quota', $quota);
  512. $this->triggerChange('quota', $quota, $oldQuota);
  513. }
  514. \OC_Helper::clearStorageInfo('/' . $this->uid . '/files');
  515. }
  516. public function getManagerUids(): array {
  517. $encodedUids = $this->config->getUserValue(
  518. $this->uid,
  519. 'settings',
  520. self::CONFIG_KEY_MANAGERS,
  521. '[]'
  522. );
  523. return json_decode($encodedUids, false, 512, JSON_THROW_ON_ERROR);
  524. }
  525. public function setManagerUids(array $uids): void {
  526. $oldUids = $this->getManagerUids();
  527. $this->config->setUserValue(
  528. $this->uid,
  529. 'settings',
  530. self::CONFIG_KEY_MANAGERS,
  531. json_encode($uids, JSON_THROW_ON_ERROR)
  532. );
  533. $this->triggerChange('managers', $uids, $oldUids);
  534. }
  535. /**
  536. * get the avatar image if it exists
  537. *
  538. * @param int $size
  539. * @return IImage|null
  540. * @since 9.0.0
  541. */
  542. public function getAvatarImage($size) {
  543. // delay the initialization
  544. if (is_null($this->avatarManager)) {
  545. $this->avatarManager = \OC::$server->get(IAvatarManager::class);
  546. }
  547. $avatar = $this->avatarManager->getAvatar($this->uid);
  548. $image = $avatar->get($size);
  549. if ($image) {
  550. return $image;
  551. }
  552. return null;
  553. }
  554. /**
  555. * get the federation cloud id
  556. *
  557. * @return string
  558. * @since 9.0.0
  559. */
  560. public function getCloudId() {
  561. $uid = $this->getUID();
  562. $server = rtrim($this->urlGenerator->getAbsoluteURL('/'), '/');
  563. if (str_ends_with($server, '/index.php')) {
  564. $server = substr($server, 0, -10);
  565. }
  566. $server = $this->removeProtocolFromUrl($server);
  567. return $uid . '@' . $server;
  568. }
  569. private function removeProtocolFromUrl(string $url): string {
  570. if (str_starts_with($url, 'https://')) {
  571. return substr($url, strlen('https://'));
  572. }
  573. return $url;
  574. }
  575. public function triggerChange($feature, $value = null, $oldValue = null) {
  576. $this->dispatcher->dispatchTyped(new UserChangedEvent($this, $feature, $value, $oldValue));
  577. if ($this->emitter) {
  578. $this->emitter->emit('\OC\User', 'changeUser', [$this, $feature, $value, $oldValue]);
  579. }
  580. }
  581. }