user.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Björn Schießle <schiessle@owncloud.com>
  5. * @author Frank Karlitschek <frank@owncloud.org>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Joas Schilling <nickvergessen@owncloud.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lorenzo M. Catucci <lorenzo@sancho.ccd.uniroma2.it>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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. /**
  31. * Public interface of ownCloud for apps to use.
  32. * User Class
  33. *
  34. */
  35. // use OCP namespace for all classes that are considered public.
  36. // This means that they should be used by apps instead of the internal ownCloud classes
  37. namespace OCP;
  38. /**
  39. * This class provides access to the user management. You can get information
  40. * about the currently logged in user and the permissions for example
  41. * @since 5.0.0
  42. */
  43. class User {
  44. /**
  45. * Get the user id of the user currently logged in.
  46. * @return string uid or false
  47. * @deprecated 8.0.0 Use \OC::$server->getUserSession()->getUser()->getUID()
  48. * @since 5.0.0
  49. */
  50. public static function getUser() {
  51. return \OC_User::getUser();
  52. }
  53. /**
  54. * Get a list of all users
  55. * @param string $search search pattern
  56. * @param int|null $limit
  57. * @param int|null $offset
  58. * @return array an array of all uids
  59. * @deprecated 8.1.0 use method search() of \OCP\IUserManager - \OC::$server->getUserManager()
  60. * @since 5.0.0
  61. */
  62. public static function getUsers( $search = '', $limit = null, $offset = null ) {
  63. return \OC_User::getUsers( $search, $limit, $offset );
  64. }
  65. /**
  66. * Get the user display name of the user currently logged in.
  67. * @param string|null $user user id or null for current user
  68. * @return string display name
  69. * @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method
  70. * get() of \OCP\IUserManager - \OC::$server->getUserManager()
  71. * @since 5.0.0
  72. */
  73. public static function getDisplayName( $user = null ) {
  74. return \OC_User::getDisplayName( $user );
  75. }
  76. /**
  77. * Get a list of all display names and user ids.
  78. * @param string $search search pattern
  79. * @param int|null $limit
  80. * @param int|null $offset
  81. * @return array an array of all display names (value) and the correspondig uids (key)
  82. * @deprecated 8.1.0 use method searchDisplayName() of \OCP\IUserManager - \OC::$server->getUserManager()
  83. * @since 5.0.0
  84. */
  85. public static function getDisplayNames( $search = '', $limit = null, $offset = null ) {
  86. return \OC_User::getDisplayNames( $search, $limit, $offset );
  87. }
  88. /**
  89. * Check if the user is logged in
  90. * @return boolean
  91. * @since 5.0.0
  92. */
  93. public static function isLoggedIn() {
  94. return \OC_User::isLoggedIn();
  95. }
  96. /**
  97. * Check if a user exists
  98. * @param string $uid the username
  99. * @param string $excludingBackend (default none)
  100. * @return boolean
  101. * @deprecated 8.1.0 use method userExists() of \OCP\IUserManager - \OC::$server->getUserManager()
  102. * @since 5.0.0
  103. */
  104. public static function userExists( $uid, $excludingBackend = null ) {
  105. return \OC_User::userExists( $uid, $excludingBackend );
  106. }
  107. /**
  108. * Logs the user out including all the session data
  109. * Logout, destroys session
  110. * @deprecated 8.0.0 Use \OC::$server->getUserSession()->logout();
  111. * @since 5.0.0
  112. */
  113. public static function logout() {
  114. \OC_User::logout();
  115. }
  116. /**
  117. * Check if the password is correct
  118. * @param string $uid The username
  119. * @param string $password The password
  120. * @return string|false username on success, false otherwise
  121. *
  122. * Check if the password is correct without logging in the user
  123. * @deprecated 8.0.0 Use \OC::$server->getUserManager()->checkPassword();
  124. * @since 5.0.0
  125. */
  126. public static function checkPassword( $uid, $password ) {
  127. return \OC_User::checkPassword( $uid, $password );
  128. }
  129. /**
  130. * Check if the user is a admin, redirects to home if not
  131. * @since 5.0.0
  132. */
  133. public static function checkAdminUser() {
  134. \OC_Util::checkAdminUser();
  135. }
  136. /**
  137. * Check if the user is logged in, redirects to home if not. With
  138. * redirect URL parameter to the request URI.
  139. * @since 5.0.0
  140. */
  141. public static function checkLoggedIn() {
  142. \OC_Util::checkLoggedIn();
  143. }
  144. }