user.php 3.4 KB

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