1
0

Backend.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\User;
  26. use OCP\UserInterface;
  27. /**
  28. * Abstract base class for user management. Provides methods for querying backend
  29. * capabilities.
  30. */
  31. abstract class Backend implements UserInterface {
  32. /**
  33. * error code for functions not provided by the user backend
  34. */
  35. public const NOT_IMPLEMENTED = -501;
  36. /**
  37. * actions that user backends can define
  38. */
  39. public const CREATE_USER = 1; // 1 << 0
  40. public const SET_PASSWORD = 16; // 1 << 4
  41. public const CHECK_PASSWORD = 256; // 1 << 8
  42. public const GET_HOME = 4096; // 1 << 12
  43. public const GET_DISPLAYNAME = 65536; // 1 << 16
  44. public const SET_DISPLAYNAME = 1048576; // 1 << 20
  45. public const PROVIDE_AVATAR = 16777216; // 1 << 24
  46. public const COUNT_USERS = 268435456; // 1 << 28
  47. protected $possibleActions = [
  48. self::CREATE_USER => 'createUser',
  49. self::SET_PASSWORD => 'setPassword',
  50. self::CHECK_PASSWORD => 'checkPassword',
  51. self::GET_HOME => 'getHome',
  52. self::GET_DISPLAYNAME => 'getDisplayName',
  53. self::SET_DISPLAYNAME => 'setDisplayName',
  54. self::PROVIDE_AVATAR => 'canChangeAvatar',
  55. self::COUNT_USERS => 'countUsers',
  56. ];
  57. /**
  58. * Get all supported actions
  59. * @return int bitwise-or'ed actions
  60. *
  61. * Returns the supported actions as int to be
  62. * compared with self::CREATE_USER etc.
  63. */
  64. public function getSupportedActions() {
  65. $actions = 0;
  66. foreach ($this->possibleActions as $action => $methodName) {
  67. if (method_exists($this, $methodName)) {
  68. $actions |= $action;
  69. }
  70. }
  71. return $actions;
  72. }
  73. /**
  74. * Check if backend implements actions
  75. * @param int $actions bitwise-or'ed actions
  76. * @return boolean
  77. *
  78. * Returns the supported actions as int to be
  79. * compared with self::CREATE_USER etc.
  80. */
  81. public function implementsActions($actions) {
  82. return (bool)($this->getSupportedActions() & $actions);
  83. }
  84. /**
  85. * delete a user
  86. * @param string $uid The username of the user to delete
  87. * @return bool
  88. *
  89. * Deletes a user
  90. */
  91. public function deleteUser($uid) {
  92. return false;
  93. }
  94. /**
  95. * Get a list of all users
  96. *
  97. * @param string $search
  98. * @param null|int $limit
  99. * @param null|int $offset
  100. * @return string[] an array of all uids
  101. */
  102. public function getUsers($search = '', $limit = null, $offset = null) {
  103. return [];
  104. }
  105. /**
  106. * check if a user exists
  107. * @param string $uid the username
  108. * @return boolean
  109. */
  110. public function userExists($uid) {
  111. return false;
  112. }
  113. /**
  114. * get the user's home directory
  115. * @param string $uid the username
  116. * @return boolean
  117. */
  118. public function getHome($uid) {
  119. return false;
  120. }
  121. /**
  122. * get display name of the user
  123. * @param string $uid user ID of the user
  124. * @return string display name
  125. */
  126. public function getDisplayName($uid) {
  127. return $uid;
  128. }
  129. /**
  130. * Get a list of all display names and user ids.
  131. *
  132. * @param string $search
  133. * @param int|null $limit
  134. * @param int|null $offset
  135. * @return array an array of all displayNames (value) and the corresponding uids (key)
  136. */
  137. public function getDisplayNames($search = '', $limit = null, $offset = null) {
  138. $displayNames = [];
  139. $users = $this->getUsers($search, $limit, $offset);
  140. foreach ($users as $user) {
  141. $displayNames[$user] = $user;
  142. }
  143. return $displayNames;
  144. }
  145. /**
  146. * Check if a user list is available or not
  147. * @return boolean if users can be listed or not
  148. */
  149. public function hasUserListings() {
  150. return false;
  151. }
  152. }