user.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. */
  39. public static function getUser() {
  40. return \OC_User::getUser();
  41. }
  42. /**
  43. * Get a list of all users
  44. * @param string search pattern
  45. * @param int limit
  46. * @param int offset
  47. * @return array with all uids
  48. */
  49. public static function getUsers( $search = '', $limit = null, $offset = null ) {
  50. return \OC_User::getUsers( $search, $limit, $offset );
  51. }
  52. /**
  53. * Get the user display name of the user currently logged in.
  54. * @param string user id or null for current user
  55. * @return string display name
  56. */
  57. public static function getDisplayName( $user = null ) {
  58. return \OC_User::getDisplayName( $user );
  59. }
  60. /**
  61. * Get a list of all display names and user ids.
  62. * @param string search pattern
  63. * @param int limit
  64. * @param int offset
  65. * @return array with all display names (value) and the correspondig uids (key)
  66. */
  67. public static function getDisplayNames( $search = '', $limit = null, $offset = null ) {
  68. return \OC_User::getDisplayNames( $search, $limit, $offset );
  69. }
  70. /**
  71. * Check if the user is logged in
  72. * @return boolean
  73. */
  74. public static function isLoggedIn() {
  75. return \OC_User::isLoggedIn();
  76. }
  77. /**
  78. * Check if a user exists
  79. * @param string $uid the username
  80. * @param string $excludingBackend (default none)
  81. * @return boolean
  82. */
  83. public static function userExists( $uid, $excludingBackend = null ) {
  84. return \OC_User::userExists( $uid, $excludingBackend );
  85. }
  86. /**
  87. * Logs the user out including all the session data
  88. * Logout, destroys session
  89. */
  90. public static function logout() {
  91. \OC_User::logout();
  92. }
  93. /**
  94. * Check if the password is correct
  95. * @param string The username
  96. * @param string The password
  97. * @return mixed username on success, false otherwise
  98. *
  99. * Check if the password is correct without logging in the user
  100. */
  101. public static function checkPassword( $uid, $password ) {
  102. return \OC_User::checkPassword( $uid, $password );
  103. }
  104. /**
  105. * Check if the user is a admin, redirects to home if not
  106. */
  107. public static function checkAdminUser() {
  108. \OC_Util::checkAdminUser();
  109. }
  110. /**
  111. * Check if the user is logged in, redirects to home if not. With
  112. * redirect URL parameter to the request URI.
  113. */
  114. public static function checkLoggedIn() {
  115. \OC_Util::checkLoggedIn();
  116. }
  117. }