user.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * Public interface of ownCloud for apps to use.
  24. * User Class
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. /**
  31. * This class provides access to the user management. You can get information
  32. * about the currently logged in user and the permissions for example
  33. */
  34. class User {
  35. /**
  36. * Get the user id of the user currently logged in.
  37. * @return string uid or false
  38. * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID()
  39. */
  40. public static function getUser() {
  41. return \OC_User::getUser();
  42. }
  43. /**
  44. * Get a list of all users
  45. * @param string $search search pattern
  46. * @param int|null $limit
  47. * @param int|null $offset
  48. * @return array an array of all uids
  49. */
  50. public static function getUsers( $search = '', $limit = null, $offset = null ) {
  51. return \OC_User::getUsers( $search, $limit, $offset );
  52. }
  53. /**
  54. * Get the user display name of the user currently logged in.
  55. * @param string|null $user user id or null for current user
  56. * @return string display name
  57. */
  58. public static function getDisplayName( $user = null ) {
  59. return \OC_User::getDisplayName( $user );
  60. }
  61. /**
  62. * Get a list of all display names and user ids.
  63. * @param string $search search pattern
  64. * @param int|null $limit
  65. * @param int|null $offset
  66. * @return array an array of all display names (value) and the correspondig uids (key)
  67. */
  68. public static function getDisplayNames( $search = '', $limit = null, $offset = null ) {
  69. return \OC_User::getDisplayNames( $search, $limit, $offset );
  70. }
  71. /**
  72. * Check if the user is logged in
  73. * @return boolean
  74. */
  75. public static function isLoggedIn() {
  76. return \OC_User::isLoggedIn();
  77. }
  78. /**
  79. * Check if a user exists
  80. * @param string $uid the username
  81. * @param string $excludingBackend (default none)
  82. * @return boolean
  83. */
  84. public static function userExists( $uid, $excludingBackend = null ) {
  85. return \OC_User::userExists( $uid, $excludingBackend );
  86. }
  87. /**
  88. * Logs the user out including all the session data
  89. * Logout, destroys session
  90. * @deprecated Use \OC::$server->getUserSession()->logout();
  91. */
  92. public static function logout() {
  93. \OC_User::logout();
  94. }
  95. /**
  96. * Check if the password is correct
  97. * @param string $uid The username
  98. * @param string $password The password
  99. * @return string|false username on success, false otherwise
  100. *
  101. * Check if the password is correct without logging in the user
  102. * @deprecated Use \OC::$server->getUserManager()->checkPassword();
  103. */
  104. public static function checkPassword( $uid, $password ) {
  105. return \OC_User::checkPassword( $uid, $password );
  106. }
  107. /**
  108. * Check if the user is a admin, redirects to home if not
  109. */
  110. public static function checkAdminUser() {
  111. \OC_Util::checkAdminUser();
  112. }
  113. /**
  114. * Check if the user is logged in, redirects to home if not. With
  115. * redirect URL parameter to the request URI.
  116. */
  117. public static function checkLoggedIn() {
  118. \OC_Util::checkLoggedIn();
  119. }
  120. }