1
0

User.php 4.9 KB

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