User.php 20 KB

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