WebService.class.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Base class for Web Services
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.webservices
  7. */
  8. abstract class WebService
  9. {
  10. protected $apiKey;
  11. /**
  12. * Class constructor
  13. */
  14. public function __construct()
  15. {
  16. $this->apiKey = null;
  17. }
  18. /**
  19. * Set the api key
  20. * @param string $apiKey The api key
  21. */
  22. public function setApiKey($apiKey)
  23. {
  24. $this->apiKey = $apiKey;
  25. }
  26. /**
  27. * @abstract
  28. */
  29. abstract public function getApiKey($username);
  30. /**
  31. * Check whether the username and password are valid
  32. * @param string $username The username
  33. * @param string $password the password
  34. * @return boolean Whether the password belongs to the username return true. Otherwise return false
  35. */
  36. public static function isValidUser($username, $password)
  37. {
  38. if (empty($username) || empty($password)) {
  39. return false;
  40. }
  41. $user = UserManager::getRepository()->findOneBy([
  42. 'username' => $username
  43. ]);
  44. if (empty($user)) {
  45. return false;
  46. }
  47. return UserManager::isPasswordValid($password, $user);
  48. }
  49. }