dummy.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * dummy user backend, does not keep state, only for testing use
  24. */
  25. class OC_User_Dummy extends OC_User_Backend implements \OCP\IUserBackend {
  26. private $users = array();
  27. private $displayNames = array();
  28. /**
  29. * Create a new user
  30. *
  31. * @param string $uid The username of the user to create
  32. * @param string $password The password of the new user
  33. * @return bool
  34. *
  35. * Creates a new user. Basic checking of username is done in OC_User
  36. * itself, not in its subclasses.
  37. */
  38. public function createUser($uid, $password) {
  39. if (isset($this->users[$uid])) {
  40. return false;
  41. } else {
  42. $this->users[$uid] = $password;
  43. return true;
  44. }
  45. }
  46. /**
  47. * delete a user
  48. *
  49. * @param string $uid The username of the user to delete
  50. * @return bool
  51. *
  52. * Deletes a user
  53. */
  54. public function deleteUser($uid) {
  55. if (isset($this->users[$uid])) {
  56. unset($this->users[$uid]);
  57. return true;
  58. } else {
  59. return false;
  60. }
  61. }
  62. /**
  63. * Set password
  64. *
  65. * @param string $uid The username
  66. * @param string $password The new password
  67. * @return bool
  68. *
  69. * Change the password of a user
  70. */
  71. public function setPassword($uid, $password) {
  72. if (isset($this->users[$uid])) {
  73. $this->users[$uid] = $password;
  74. return true;
  75. } else {
  76. return false;
  77. }
  78. }
  79. /**
  80. * Check if the password is correct
  81. *
  82. * @param string $uid The username
  83. * @param string $password The password
  84. * @return string
  85. *
  86. * Check if the password is correct without logging in the user
  87. * returns the user id or false
  88. */
  89. public function checkPassword($uid, $password) {
  90. if (isset($this->users[$uid]) && $this->users[$uid] === $password) {
  91. return $uid;
  92. } else {
  93. return false;
  94. }
  95. }
  96. /**
  97. * Get a list of all users
  98. *
  99. * @param string $search
  100. * @param int $limit
  101. * @param int $offset
  102. * @return string[] with all uids
  103. *
  104. * Get a list of all users.
  105. */
  106. public function getUsers($search = '', $limit = null, $offset = null) {
  107. if (empty($search)) {
  108. return array_keys($this->users);
  109. }
  110. $result = array();
  111. foreach (array_keys($this->users) as $user) {
  112. if (stripos($user, $search) !== false) {
  113. $result[] = $user;
  114. }
  115. }
  116. return $result;
  117. }
  118. /**
  119. * check if a user exists
  120. *
  121. * @param string $uid the username
  122. * @return boolean
  123. */
  124. public function userExists($uid) {
  125. return isset($this->users[$uid]);
  126. }
  127. /**
  128. * @return bool
  129. */
  130. public function hasUserListings() {
  131. return true;
  132. }
  133. /**
  134. * counts the users in the database
  135. *
  136. * @return int|bool
  137. */
  138. public function countUsers() {
  139. return 0;
  140. }
  141. public function setDisplayName($uid, $displayName) {
  142. $this->displayNames[$uid] = $displayName;
  143. }
  144. public function getDisplayName($uid) {
  145. return isset($this->displayNames[$uid])? $this->displayNames[$uid]: $uid;
  146. }
  147. /**
  148. * Backend name to be shown in user management
  149. * @return string the name of the backend to be shown
  150. */
  151. public function getBackendName(){
  152. return 'Dummy';
  153. }
  154. }