1
0

IUserManager.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 OCP;
  8. /**
  9. * Class Manager
  10. *
  11. * Hooks available in scope \OC\User:
  12. * - preSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
  13. * - postSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
  14. * - preDelete(\OC\User\User $user)
  15. * - postDelete(\OC\User\User $user)
  16. * - preCreateUser(string $uid, string $password)
  17. * - postCreateUser(\OC\User\User $user, string $password)
  18. * - assignedUserId(string $uid)
  19. * - preUnassignedUserId(string $uid)
  20. * - postUnassignedUserId(string $uid)
  21. *
  22. * @since 8.0.0
  23. */
  24. interface IUserManager {
  25. /**
  26. * @since 26.0.0
  27. */
  28. public const MAX_PASSWORD_LENGTH = 469;
  29. /**
  30. * register a user backend
  31. *
  32. * @param \OCP\UserInterface $backend
  33. * @since 8.0.0
  34. */
  35. public function registerBackend($backend);
  36. /**
  37. * Get the active backends
  38. * @return \OCP\UserInterface[]
  39. * @since 8.0.0
  40. */
  41. public function getBackends();
  42. /**
  43. * remove a user backend
  44. *
  45. * @param \OCP\UserInterface $backend
  46. * @since 8.0.0
  47. */
  48. public function removeBackend($backend);
  49. /**
  50. * remove all user backends
  51. * @since 8.0.0
  52. */
  53. public function clearBackends() ;
  54. /**
  55. * get a user by user id
  56. *
  57. * @param string $uid
  58. * @return \OCP\IUser|null Either the user or null if the specified user does not exist
  59. * @since 8.0.0
  60. */
  61. public function get($uid);
  62. /**
  63. * Get the display name of a user
  64. *
  65. * @param string $uid
  66. * @return string|null
  67. * @since 25.0.0
  68. */
  69. public function getDisplayName(string $uid): ?string;
  70. /**
  71. * check if a user exists
  72. *
  73. * @param string $uid
  74. * @return bool
  75. * @since 8.0.0
  76. */
  77. public function userExists($uid);
  78. /**
  79. * Check if the password is valid for the user
  80. *
  81. * @param string $loginName
  82. * @param string $password
  83. * @return IUser|false the User object on success, false otherwise
  84. * @since 8.0.0
  85. */
  86. public function checkPassword($loginName, $password);
  87. /**
  88. * search by user id
  89. *
  90. * @param string $pattern
  91. * @param int $limit
  92. * @param int $offset
  93. * @return \OCP\IUser[]
  94. * @since 8.0.0
  95. */
  96. public function search($pattern, $limit = null, $offset = null);
  97. /**
  98. * search by displayName
  99. *
  100. * @param string $pattern
  101. * @param int $limit
  102. * @param int $offset
  103. * @return \OCP\IUser[]
  104. * @since 8.0.0
  105. */
  106. public function searchDisplayName($pattern, $limit = null, $offset = null);
  107. /**
  108. * @return IUser[]
  109. * @since 28.0.0
  110. * @since 30.0.0 $search parameter added
  111. */
  112. public function getDisabledUsers(?int $limit = null, int $offset = 0, string $search = ''): array;
  113. /**
  114. * Search known users (from phonebook sync) by displayName
  115. *
  116. * @param string $searcher
  117. * @param string $pattern
  118. * @param int|null $limit
  119. * @param int|null $offset
  120. * @return IUser[]
  121. * @since 21.0.1
  122. */
  123. public function searchKnownUsersByDisplayName(string $searcher, string $pattern, ?int $limit = null, ?int $offset = null): array;
  124. /**
  125. * @param string $uid
  126. * @param string $password
  127. * @throws \InvalidArgumentException
  128. * @return false|\OCP\IUser the created user or false
  129. * @since 8.0.0
  130. */
  131. public function createUser($uid, $password);
  132. /**
  133. * @param string $uid
  134. * @param string $password
  135. * @param UserInterface $backend
  136. * @return IUser|null
  137. * @throws \InvalidArgumentException
  138. * @since 12.0.0
  139. */
  140. public function createUserFromBackend($uid, $password, UserInterface $backend);
  141. /**
  142. * Get how many users per backend exist (if supported by backend)
  143. *
  144. * @return array<string, int> an array of backend class name as key and count number as value
  145. * @since 8.0.0
  146. */
  147. public function countUsers();
  148. /**
  149. * @param \Closure $callback
  150. * @psalm-param \Closure(\OCP\IUser):void $callback
  151. * @param string $search
  152. * @since 9.0.0
  153. */
  154. public function callForAllUsers(\Closure $callback, $search = '');
  155. /**
  156. * returns how many users have logged in once
  157. *
  158. * @return int
  159. * @since 11.0.0
  160. */
  161. public function countDisabledUsers();
  162. /**
  163. * returns how many users have logged in once
  164. *
  165. * @return int
  166. * @since 11.0.0
  167. */
  168. public function countSeenUsers();
  169. /**
  170. * @param \Closure $callback
  171. * @psalm-param \Closure(\OCP\IUser):?bool $callback
  172. * @since 11.0.0
  173. */
  174. public function callForSeenUsers(\Closure $callback);
  175. /**
  176. * returns all users having the provided email set as system email address
  177. *
  178. * @param string $email
  179. * @return IUser[]
  180. * @since 9.1.0
  181. */
  182. public function getByEmail($email);
  183. /**
  184. * @param string $uid The user ID to validate
  185. * @param bool $checkDataDirectory Whether it should be checked if files for the ID exist inside the data directory
  186. * @throws \InvalidArgumentException Message is an already translated string with a reason why the ID is not valid
  187. * @since 26.0.0
  188. */
  189. public function validateUserId(string $uid, bool $checkDataDirectory = false): void;
  190. }