user.php 4.8 KB

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