apiuserhandler.class.php 733 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use Luracast\Restler\RestException;
  3. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  4. class ApiUserHandler
  5. {
  6. public $db;
  7. public function __construct()
  8. {
  9. global $db;
  10. $this->db = $db;
  11. }
  12. /**
  13. * Summary of getUser
  14. * @param int $id
  15. * @param string $apikey
  16. *
  17. * @throws Exception
  18. *
  19. * @return User
  20. */
  21. public function getUser(int $id, string $apikey): User
  22. {
  23. $user = new User($this->db);
  24. if (($user->fetch($id) < 1)
  25. || ($user->api_key !== $apikey)
  26. || (intval($user->statut) !== User::STATUS_ENABLED)) {
  27. throw new RestException(404, 'User not found');
  28. }
  29. return $user;
  30. }
  31. }