1
0

User.php 19 KB

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