user.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Lukas Reschke <lukas@owncloud.com>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. *
  15. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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. */
  43. class User {
  44. /**
  45. * Get the user id of the user currently logged in.
  46. * @return string uid or false
  47. * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID()
  48. */
  49. public static function getUser() {
  50. return \OC_User::getUser();
  51. }
  52. /**
  53. * Get a list of all users
  54. * @param string $search search pattern
  55. * @param int|null $limit
  56. * @param int|null $offset
  57. * @return array an array of all uids
  58. */
  59. public static function getUsers( $search = '', $limit = null, $offset = null ) {
  60. return \OC_User::getUsers( $search, $limit, $offset );
  61. }
  62. /**
  63. * Get the user display name of the user currently logged in.
  64. * @param string|null $user user id or null for current user
  65. * @return string display name
  66. */
  67. public static function getDisplayName( $user = null ) {
  68. return \OC_User::getDisplayName( $user );
  69. }
  70. /**
  71. * Get a list of all display names and user ids.
  72. * @param string $search search pattern
  73. * @param int|null $limit
  74. * @param int|null $offset
  75. * @return array an array of all display names (value) and the correspondig uids (key)
  76. */
  77. public static function getDisplayNames( $search = '', $limit = null, $offset = null ) {
  78. return \OC_User::getDisplayNames( $search, $limit, $offset );
  79. }
  80. /**
  81. * Check if the user is logged in
  82. * @return boolean
  83. */
  84. public static function isLoggedIn() {
  85. return \OC_User::isLoggedIn();
  86. }
  87. /**
  88. * Check if a user exists
  89. * @param string $uid the username
  90. * @param string $excludingBackend (default none)
  91. * @return boolean
  92. */
  93. public static function userExists( $uid, $excludingBackend = null ) {
  94. return \OC_User::userExists( $uid, $excludingBackend );
  95. }
  96. /**
  97. * Logs the user out including all the session data
  98. * Logout, destroys session
  99. * @deprecated Use \OC::$server->getUserSession()->logout();
  100. */
  101. public static function logout() {
  102. \OC_User::logout();
  103. }
  104. /**
  105. * Check if the password is correct
  106. * @param string $uid The username
  107. * @param string $password The password
  108. * @return string|false username on success, false otherwise
  109. *
  110. * Check if the password is correct without logging in the user
  111. * @deprecated Use \OC::$server->getUserManager()->checkPassword();
  112. */
  113. public static function checkPassword( $uid, $password ) {
  114. return \OC_User::checkPassword( $uid, $password );
  115. }
  116. /**
  117. * Check if the user is a admin, redirects to home if not
  118. */
  119. public static function checkAdminUser() {
  120. \OC_Util::checkAdminUser();
  121. }
  122. /**
  123. * Check if the user is logged in, redirects to home if not. With
  124. * redirect URL parameter to the request URI.
  125. */
  126. public static function checkLoggedIn() {
  127. \OC_Util::checkLoggedIn();
  128. }
  129. }