1
0

Backend.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 OC\User;
  8. use OCP\UserInterface;
  9. /**
  10. * Abstract base class for user management. Provides methods for querying backend
  11. * capabilities.
  12. */
  13. abstract class Backend implements UserInterface {
  14. /**
  15. * error code for functions not provided by the user backend
  16. */
  17. public const NOT_IMPLEMENTED = -501;
  18. /**
  19. * actions that user backends can define
  20. */
  21. public const CREATE_USER = 1; // 1 << 0
  22. public const SET_PASSWORD = 16; // 1 << 4
  23. public const CHECK_PASSWORD = 256; // 1 << 8
  24. public const GET_HOME = 4096; // 1 << 12
  25. public const GET_DISPLAYNAME = 65536; // 1 << 16
  26. public const SET_DISPLAYNAME = 1048576; // 1 << 20
  27. public const PROVIDE_AVATAR = 16777216; // 1 << 24
  28. public const COUNT_USERS = 268435456; // 1 << 28
  29. protected $possibleActions = [
  30. self::CREATE_USER => 'createUser',
  31. self::SET_PASSWORD => 'setPassword',
  32. self::CHECK_PASSWORD => 'checkPassword',
  33. self::GET_HOME => 'getHome',
  34. self::GET_DISPLAYNAME => 'getDisplayName',
  35. self::SET_DISPLAYNAME => 'setDisplayName',
  36. self::PROVIDE_AVATAR => 'canChangeAvatar',
  37. self::COUNT_USERS => 'countUsers',
  38. ];
  39. /**
  40. * Get all supported actions
  41. * @return int bitwise-or'ed actions
  42. *
  43. * Returns the supported actions as int to be
  44. * compared with self::CREATE_USER etc.
  45. */
  46. public function getSupportedActions() {
  47. $actions = 0;
  48. foreach ($this->possibleActions as $action => $methodName) {
  49. if (method_exists($this, $methodName)) {
  50. $actions |= $action;
  51. }
  52. }
  53. return $actions;
  54. }
  55. /**
  56. * Check if backend implements actions
  57. * @param int $actions bitwise-or'ed actions
  58. * @return boolean
  59. *
  60. * Returns the supported actions as int to be
  61. * compared with self::CREATE_USER etc.
  62. */
  63. public function implementsActions($actions) {
  64. return (bool)($this->getSupportedActions() & $actions);
  65. }
  66. /**
  67. * delete a user
  68. * @param string $uid The username of the user to delete
  69. * @return bool
  70. *
  71. * Deletes a user
  72. */
  73. public function deleteUser($uid) {
  74. return false;
  75. }
  76. /**
  77. * Get a list of all users
  78. *
  79. * @param string $search
  80. * @param null|int $limit
  81. * @param null|int $offset
  82. * @return string[] an array of all uids
  83. */
  84. public function getUsers($search = '', $limit = null, $offset = null) {
  85. return [];
  86. }
  87. /**
  88. * check if a user exists
  89. * @param string $uid the username
  90. * @return boolean
  91. */
  92. public function userExists($uid) {
  93. return false;
  94. }
  95. /**
  96. * get the user's home directory
  97. * @param string $uid the username
  98. * @return string|boolean
  99. */
  100. public function getHome(string $uid) {
  101. return false;
  102. }
  103. /**
  104. * get display name of the user
  105. * @param string $uid user ID of the user
  106. * @return string display name
  107. */
  108. public function getDisplayName($uid) {
  109. return $uid;
  110. }
  111. /**
  112. * Get a list of all display names and user ids.
  113. *
  114. * @param string $search
  115. * @param int|null $limit
  116. * @param int|null $offset
  117. * @return array an array of all displayNames (value) and the corresponding uids (key)
  118. */
  119. public function getDisplayNames($search = '', $limit = null, $offset = null) {
  120. $displayNames = [];
  121. $users = $this->getUsers($search, $limit, $offset);
  122. foreach ($users as $user) {
  123. $displayNames[$user] = $user;
  124. }
  125. return $displayNames;
  126. }
  127. /**
  128. * Check if a user list is available or not
  129. * @return boolean if users can be listed or not
  130. */
  131. public function hasUserListings() {
  132. return false;
  133. }
  134. }