You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
6.2 KiB

  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. * @since 8.0.0
  33. * @return void
  34. */
  35. public function registerBackend(UserInterface $backend);
  36. /**
  37. * Get the active backends
  38. * @return UserInterface[]
  39. * @since 8.0.0
  40. */
  41. public function getBackends();
  42. /**
  43. * remove a user backend
  44. *
  45. * @since 8.0.0
  46. * @return void
  47. */
  48. public function removeBackend(UserInterface $backend);
  49. /**
  50. * remove all user backends
  51. * @since 8.0.0
  52. * @return void
  53. */
  54. public function clearBackends();
  55. /**
  56. * get a user by user id
  57. *
  58. * @param string $uid
  59. * @return \OCP\IUser|null Either the user or null if the specified user does not exist
  60. * @since 8.0.0
  61. */
  62. public function get($uid);
  63. /**
  64. * Get the display name of a user
  65. *
  66. * @param string $uid
  67. * @return string|null
  68. * @since 25.0.0
  69. */
  70. public function getDisplayName(string $uid): ?string;
  71. /**
  72. * check if a user exists
  73. *
  74. * @param string $uid
  75. * @return bool
  76. * @since 8.0.0
  77. */
  78. public function userExists($uid);
  79. /**
  80. * Check if the password is valid for the user
  81. *
  82. * @param string $loginName
  83. * @param string $password
  84. * @return IUser|false the User object on success, false otherwise
  85. * @since 8.0.0
  86. */
  87. public function checkPassword($loginName, $password);
  88. /**
  89. * search by user id
  90. *
  91. * @param string $pattern
  92. * @param int $limit
  93. * @param int $offset
  94. * @return \OCP\IUser[]
  95. * @since 8.0.0
  96. * @deprecated 27.0.0, use searchDisplayName instead
  97. */
  98. public function search($pattern, $limit = null, $offset = null);
  99. /**
  100. * search by displayName
  101. *
  102. * @param string $pattern
  103. * @param int $limit
  104. * @param int $offset
  105. * @return \OCP\IUser[]
  106. * @since 8.0.0
  107. */
  108. public function searchDisplayName($pattern, $limit = null, $offset = null);
  109. /**
  110. * @return IUser[]
  111. * @since 28.0.0
  112. * @since 30.0.0 $search parameter added
  113. */
  114. public function getDisabledUsers(?int $limit = null, int $offset = 0, string $search = ''): array;
  115. /**
  116. * Search known users (from phonebook sync) by displayName
  117. *
  118. * @param string $searcher
  119. * @param string $pattern
  120. * @param int|null $limit
  121. * @param int|null $offset
  122. * @return IUser[]
  123. * @since 21.0.1
  124. */
  125. public function searchKnownUsersByDisplayName(string $searcher, string $pattern, ?int $limit = null, ?int $offset = null): array;
  126. /**
  127. * @param string $uid
  128. * @param string $password
  129. * @throws \InvalidArgumentException
  130. * @return false|\OCP\IUser the created user or false
  131. * @since 8.0.0
  132. */
  133. public function createUser($uid, $password);
  134. /**
  135. * @param string $uid
  136. * @param string $password
  137. * @param UserInterface $backend
  138. * @return IUser|null
  139. * @throws \InvalidArgumentException
  140. * @since 12.0.0
  141. */
  142. public function createUserFromBackend($uid, $password, UserInterface $backend);
  143. /**
  144. * Get how many users per backend exist (if supported by backend)
  145. *
  146. * @return array<string, int> an array of backend class name as key and count number as value
  147. * @since 8.0.0
  148. */
  149. public function countUsers();
  150. /**
  151. * Get how many users exists in total, whithin limit
  152. *
  153. * @param int $limit Limit the count to avoid resource waste. 0 to disable
  154. * @param bool $onlyMappedUsers Count mapped users instead of all users for compatible backends
  155. *
  156. * @since 31.0.0
  157. */
  158. public function countUsersTotal(int $limit = 0, bool $onlyMappedUsers = false): int|false;
  159. /**
  160. * @param \Closure $callback
  161. * @psalm-param \Closure(\OCP\IUser):void $callback
  162. * @param string $search
  163. * @since 9.0.0
  164. */
  165. public function callForAllUsers(\Closure $callback, $search = '');
  166. /**
  167. * returns how many users have logged in once
  168. *
  169. * @return int
  170. * @since 11.0.0
  171. */
  172. public function countDisabledUsers();
  173. /**
  174. * returns how many users have logged in once
  175. *
  176. * @return int
  177. * @since 11.0.0
  178. */
  179. public function countSeenUsers();
  180. /**
  181. * @param \Closure $callback
  182. * @psalm-param \Closure(\OCP\IUser):?bool $callback
  183. * @since 11.0.0
  184. */
  185. public function callForSeenUsers(\Closure $callback);
  186. /**
  187. * returns all users having the provided email set as system email address
  188. *
  189. * @param string $email
  190. * @return IUser[]
  191. * @since 9.1.0
  192. */
  193. public function getByEmail($email);
  194. /**
  195. * @param string $uid The user ID to validate
  196. * @param bool $checkDataDirectory Whether it should be checked if files for the ID exist inside the data directory
  197. * @throws \InvalidArgumentException Message is an already translated string with a reason why the ID is not valid
  198. * @since 26.0.0
  199. */
  200. public function validateUserId(string $uid, bool $checkDataDirectory = false): void;
  201. /**
  202. * Gets the list of users sorted by lastLogin, from most recent to least recent
  203. *
  204. * @param int|null $limit how many records to fetch
  205. * @param int $offset from which offset to fetch
  206. * @param string $search search users based on search params
  207. * @return list<string> list of user IDs
  208. * @since 30.0.0
  209. */
  210. public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string $search = ''): array;
  211. /**
  212. * Gets the list of users.
  213. * An iterator is returned allowing the caller to stop the iteration at any time.
  214. * The offset argument allows the caller to continue the iteration at a specific offset.
  215. *
  216. * @param int $offset from which offset to fetch
  217. * @param int|null $limit maximum number of records to fetch
  218. * @return \Iterator<IUser> list of IUser object
  219. * @since 32.0.0
  220. */
  221. public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator;
  222. }