Single-sign-on and self-serve account management. https://netsyms.biz/apps/accounthub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

userinfo.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /**
  6. * Get user info for the given username.
  7. * @param int $u username
  8. * @return [string] Array of [uid, username, name]
  9. */
  10. function getUserByUsername($u) {
  11. $client = new GuzzleHttp\Client();
  12. $response = $client
  13. ->request('POST', PORTAL_API, [
  14. 'form_params' => [
  15. 'key' => PORTAL_KEY,
  16. 'action' => "userinfo",
  17. 'username' => $u
  18. ]
  19. ]);
  20. if ($response->getStatusCode() > 299) {
  21. sendError("Login server error: " . $response->getBody());
  22. }
  23. $resp = json_decode($response->getBody(), TRUE);
  24. if ($resp['status'] == "OK") {
  25. return $resp['data'];
  26. } else {
  27. // this shouldn't happen, but in case it does just fake it.
  28. return ["name" => $u, "username" => $u, "uid" => $u];
  29. }
  30. }
  31. /**
  32. * Get user info for the given UID.
  33. * @param int $u user ID
  34. * @return [string] Array of [uid, username, name]
  35. */
  36. function getUserByID($u) {
  37. $client = new GuzzleHttp\Client();
  38. $response = $client
  39. ->request('POST', PORTAL_API, [
  40. 'form_params' => [
  41. 'key' => PORTAL_KEY,
  42. 'action' => "userinfo",
  43. 'uid' => $u
  44. ]
  45. ]);
  46. if ($response->getStatusCode() > 299) {
  47. sendError("Login server error: " . $response->getBody());
  48. }
  49. $resp = json_decode($response->getBody(), TRUE);
  50. if ($resp['status'] == "OK") {
  51. return $resp['data'];
  52. } else {
  53. // this shouldn't happen, but in case it does just fake it.
  54. return ["name" => $u, "username" => $u, "uid" => $u];
  55. }
  56. }
  57. /**
  58. * Check if the first UID is a manager of the second UID.
  59. * @param int $m Manager UID
  60. * @param int $e Employee UID
  61. * @return boolean
  62. */
  63. function isManagerOf($m, $e) {
  64. $client = new GuzzleHttp\Client();
  65. $response = $client
  66. ->request('POST', PORTAL_API, [
  67. 'form_params' => [
  68. 'key' => PORTAL_KEY,
  69. 'action' => "ismanagerof",
  70. 'manager' => $m,
  71. 'employee' => $e,
  72. 'uid' => 1
  73. ]
  74. ]);
  75. if ($response->getStatusCode() > 299) {
  76. sendError("Login server error: " . $response->getBody());
  77. }
  78. $resp = json_decode($response->getBody(), TRUE);
  79. if ($resp['status'] == "OK") {
  80. return $resp['managerof'] === true;
  81. } else {
  82. // this shouldn't happen, but in case it does just fake it.
  83. return false;
  84. }
  85. }
  86. /**
  87. * Get an array of UIDs the given UID is a manager of.
  88. * @param int $manageruid The UID of the manager to find employees for.
  89. * @return [int]
  90. */
  91. function getManagedUIDs($manageruid) {
  92. $client = new GuzzleHttp\Client();
  93. $response = $client
  94. ->request('POST', PORTAL_API, [
  95. 'form_params' => [
  96. 'key' => PORTAL_KEY,
  97. 'action' => "getmanaged",
  98. 'uid' => $manageruid
  99. ]
  100. ]);
  101. if ($response->getStatusCode() > 299) {
  102. sendError("Login server error: " . $response->getBody());
  103. }
  104. $resp = json_decode($response->getBody(), TRUE);
  105. if ($resp['status'] == "OK") {
  106. return $resp['employees'];
  107. } else {
  108. return [];
  109. }
  110. }