IUserManager.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCP;
  31. /**
  32. * Class Manager
  33. *
  34. * Hooks available in scope \OC\User:
  35. * - preSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
  36. * - postSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
  37. * - preDelete(\OC\User\User $user)
  38. * - postDelete(\OC\User\User $user)
  39. * - preCreateUser(string $uid, string $password)
  40. * - postCreateUser(\OC\User\User $user, string $password)
  41. * - assignedUserId(string $uid)
  42. * - preUnassignedUserId(string $uid)
  43. * - postUnassignedUserId(string $uid)
  44. *
  45. * @since 8.0.0
  46. */
  47. interface IUserManager {
  48. /**
  49. * @since 26.0.0
  50. */
  51. public const MAX_PASSWORD_LENGTH = 469;
  52. /**
  53. * register a user backend
  54. *
  55. * @param \OCP\UserInterface $backend
  56. * @since 8.0.0
  57. */
  58. public function registerBackend($backend);
  59. /**
  60. * Get the active backends
  61. * @return \OCP\UserInterface[]
  62. * @since 8.0.0
  63. */
  64. public function getBackends();
  65. /**
  66. * remove a user backend
  67. *
  68. * @param \OCP\UserInterface $backend
  69. * @since 8.0.0
  70. */
  71. public function removeBackend($backend);
  72. /**
  73. * remove all user backends
  74. * @since 8.0.0
  75. */
  76. public function clearBackends() ;
  77. /**
  78. * get a user by user id
  79. *
  80. * @param string $uid
  81. * @return \OCP\IUser|null Either the user or null if the specified user does not exist
  82. * @since 8.0.0
  83. */
  84. public function get($uid);
  85. /**
  86. * Get the display name of a user
  87. *
  88. * @param string $uid
  89. * @return string|null
  90. * @since 25.0.0
  91. */
  92. public function getDisplayName(string $uid): ?string;
  93. /**
  94. * check if a user exists
  95. *
  96. * @param string $uid
  97. * @return bool
  98. * @since 8.0.0
  99. */
  100. public function userExists($uid);
  101. /**
  102. * Check if the password is valid for the user
  103. *
  104. * @param string $loginName
  105. * @param string $password
  106. * @return IUser|false the User object on success, false otherwise
  107. * @since 8.0.0
  108. */
  109. public function checkPassword($loginName, $password);
  110. /**
  111. * search by user id
  112. *
  113. * @param string $pattern
  114. * @param int $limit
  115. * @param int $offset
  116. * @return \OCP\IUser[]
  117. * @since 8.0.0
  118. */
  119. public function search($pattern, $limit = null, $offset = null);
  120. /**
  121. * search by displayName
  122. *
  123. * @param string $pattern
  124. * @param int $limit
  125. * @param int $offset
  126. * @return \OCP\IUser[]
  127. * @since 8.0.0
  128. */
  129. public function searchDisplayName($pattern, $limit = null, $offset = null);
  130. /**
  131. * @return IUser[]
  132. * @since 28.0.0
  133. * @since 28.0.7 $search parameter added
  134. */
  135. public function getDisabledUsers(?int $limit = null, int $offset = 0, string $search = ''): array;
  136. /**
  137. * Search known users (from phonebook sync) by displayName
  138. *
  139. * @param string $searcher
  140. * @param string $pattern
  141. * @param int|null $limit
  142. * @param int|null $offset
  143. * @return IUser[]
  144. * @since 21.0.1
  145. */
  146. public function searchKnownUsersByDisplayName(string $searcher, string $pattern, ?int $limit = null, ?int $offset = null): array;
  147. /**
  148. * @param string $uid
  149. * @param string $password
  150. * @throws \InvalidArgumentException
  151. * @return false|\OCP\IUser the created user or false
  152. * @since 8.0.0
  153. */
  154. public function createUser($uid, $password);
  155. /**
  156. * @param string $uid
  157. * @param string $password
  158. * @param UserInterface $backend
  159. * @return IUser|null
  160. * @throws \InvalidArgumentException
  161. * @since 12.0.0
  162. */
  163. public function createUserFromBackend($uid, $password, UserInterface $backend);
  164. /**
  165. * Get how many users per backend exist (if supported by backend)
  166. *
  167. * @return array<string, int> an array of backend class name as key and count number as value
  168. * @since 8.0.0
  169. */
  170. public function countUsers();
  171. /**
  172. * @param \Closure $callback
  173. * @psalm-param \Closure(\OCP\IUser):void $callback
  174. * @param string $search
  175. * @since 9.0.0
  176. */
  177. public function callForAllUsers(\Closure $callback, $search = '');
  178. /**
  179. * returns how many users have logged in once
  180. *
  181. * @return int
  182. * @since 11.0.0
  183. */
  184. public function countDisabledUsers();
  185. /**
  186. * returns how many users have logged in once
  187. *
  188. * @return int
  189. * @since 11.0.0
  190. */
  191. public function countSeenUsers();
  192. /**
  193. * @param \Closure $callback
  194. * @psalm-param \Closure(\OCP\IUser):?bool $callback
  195. * @since 11.0.0
  196. */
  197. public function callForSeenUsers(\Closure $callback);
  198. /**
  199. * returns all users having the provided email set as system email address
  200. *
  201. * @param string $email
  202. * @return IUser[]
  203. * @since 9.1.0
  204. */
  205. public function getByEmail($email);
  206. /**
  207. * @param string $uid The user ID to validate
  208. * @param bool $checkDataDirectory Whether it should be checked if files for the ID exist inside the data directory
  209. * @throws \InvalidArgumentException Message is an already translated string with a reason why the ID is not valid
  210. * @since 26.0.0
  211. */
  212. public function validateUserId(string $uid, bool $checkDataDirectory = false): void;
  213. }