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.
 
 
 
 
 

72 lines
2.1 KiB

  1. <?php
  2. namespace dokuwiki\Remote\Response;
  3. /**
  4. * Represents a user
  5. */
  6. class User extends ApiResponse
  7. {
  8. /** @var string The login name of the user */
  9. public $login;
  10. /** @var string The full name of the user */
  11. public $name;
  12. /** @var string The email address of the user */
  13. public $mail;
  14. /** @var string[] The groups the user is in */
  15. public $groups;
  16. /** @var bool Whether the user is a super user */
  17. public bool $isadmin;
  18. /** @var bool Whether the user is a manager */
  19. public bool $ismanager;
  20. /**
  21. * @param string $login defaults to the current user
  22. * @param string $name
  23. * @param string $mail
  24. * @param string[] $groups
  25. */
  26. public function __construct($login = '', $name = '', $mail = '', $groups = [])
  27. {
  28. global $INPUT;
  29. global $USERINFO;
  30. global $auth;
  31. $this->login = $login;
  32. $this->name = $name;
  33. $this->mail = $mail;
  34. $this->groups = $groups;
  35. if ($this->login === '') {
  36. $this->login = $INPUT->server->str('REMOTE_USER');
  37. }
  38. if ($this->login === '') {
  39. throw new \RuntimeException('No user available');
  40. }
  41. // for current user, use $USERINFO to fill up
  42. if ($this->login === $INPUT->server->str('REMOTE_USER')) {
  43. $this->name = $this->name ?: $USERINFO['name'];
  44. $this->mail = $this->mail ?: $USERINFO['mail'];
  45. $this->groups = $this->groups ?: $USERINFO['grps'];
  46. } else {
  47. // for other users, use auth_getUserData to fill up
  48. $userData = $auth->getUserData($this->login);
  49. $this->name = $this->name ?: $userData['name'];
  50. $this->mail = $this->mail ?: $userData['mail'];
  51. $this->groups = $this->groups ?: $userData['grps'];
  52. }
  53. // check for admin and manager
  54. $this->isadmin = auth_isAdmin($this->login, $this->groups);
  55. $this->ismanager = auth_isManager($this->login, $this->groups);
  56. }
  57. /** @inheritdoc */
  58. public function __toString()
  59. {
  60. return $this->login;
  61. }
  62. }