backend.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @author Dominik Schmidt
  7. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  8. * @copyright 2011 Dominik Schmidt dev@dominik-schmidt.de
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * error code for functions not provided by the user backend
  26. */
  27. define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501);
  28. /**
  29. * actions that user backends can define
  30. */
  31. define('OC_USER_BACKEND_CREATE_USER', 0x000001);
  32. define('OC_USER_BACKEND_SET_PASSWORD', 0x000010);
  33. define('OC_USER_BACKEND_CHECK_PASSWORD', 0x000100);
  34. define('OC_USER_BACKEND_GET_HOME', 0x001000);
  35. define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x010000);
  36. define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x100000);
  37. /**
  38. * Abstract base class for user management. Provides methods for querying backend
  39. * capabilities.
  40. *
  41. * Subclass this for your own backends, and see OC_User_Example for descriptions
  42. */
  43. abstract class OC_User_Backend implements OC_User_Interface {
  44. protected $possibleActions = array(
  45. OC_USER_BACKEND_CREATE_USER => 'createUser',
  46. OC_USER_BACKEND_SET_PASSWORD => 'setPassword',
  47. OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword',
  48. OC_USER_BACKEND_GET_HOME => 'getHome',
  49. OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName',
  50. OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName',
  51. );
  52. /**
  53. * @brief Get all supported actions
  54. * @return int bitwise-or'ed actions
  55. *
  56. * Returns the supported actions as int to be
  57. * compared with OC_USER_BACKEND_CREATE_USER etc.
  58. */
  59. public function getSupportedActions() {
  60. $actions = 0;
  61. foreach($this->possibleActions AS $action => $methodName) {
  62. if(method_exists($this, $methodName)) {
  63. $actions |= $action;
  64. }
  65. }
  66. return $actions;
  67. }
  68. /**
  69. * @brief Check if backend implements actions
  70. * @param int $actions bitwise-or'ed actions
  71. * @return boolean
  72. *
  73. * Returns the supported actions as int to be
  74. * compared with OC_USER_BACKEND_CREATE_USER etc.
  75. */
  76. public function implementsActions($actions) {
  77. return (bool)($this->getSupportedActions() & $actions);
  78. }
  79. /**
  80. * @brief delete a user
  81. * @param string $uid The username of the user to delete
  82. * @return bool
  83. *
  84. * Deletes a user
  85. */
  86. public function deleteUser( $uid ) {
  87. return false;
  88. }
  89. /**
  90. * @brief Get a list of all users
  91. * @returns array with all uids
  92. *
  93. * Get a list of all users.
  94. */
  95. public function getUsers($search = '', $limit = null, $offset = null) {
  96. return array();
  97. }
  98. /**
  99. * @brief check if a user exists
  100. * @param string $uid the username
  101. * @return boolean
  102. */
  103. public function userExists($uid) {
  104. return false;
  105. }
  106. /**
  107. * @brief get the user's home directory
  108. * @param string $uid the username
  109. * @return boolean
  110. */
  111. public function getHome($uid) {
  112. return false;
  113. }
  114. /**
  115. * @brief get display name of the user
  116. * @param string $uid user ID of the user
  117. * @return string display name
  118. */
  119. public function getDisplayName($uid) {
  120. return $uid;
  121. }
  122. /**
  123. * @brief Get a list of all display names
  124. * @returns array with all displayNames (value) and the corresponding uids (key)
  125. *
  126. * Get a list of all display names and user ids.
  127. */
  128. public function getDisplayNames($search = '', $limit = null, $offset = null) {
  129. $displayNames = array();
  130. $users = $this->getUsers($search, $limit, $offset);
  131. foreach ( $users as $user) {
  132. $displayNames[$user] = $user;
  133. }
  134. return $displayNames;
  135. }
  136. /**
  137. * @brief Check if a user list is available or not
  138. * @return boolean if users can be listed or not
  139. */
  140. public function hasUserListings() {
  141. return false;
  142. }
  143. }