token.php 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class token {
  3. private $db = null;
  4. public function __construct() {
  5. $this->db = new db();
  6. }
  7. private function getRole($token) {
  8. $dbAction = $this->db->prepare("SELECT role FROM clients WHERE token = ?");
  9. $dbAction->bind_param('s',$token);
  10. $dbAction->execute();
  11. $dbAction->store_result();
  12. $dbAction->bind_result($role);
  13. $dbAction->fetch();
  14. if ($dbAction->num_rows() == 1){
  15. return $role;
  16. }
  17. return false;
  18. }
  19. public function isAdmin($token) {
  20. if($this->getRole($token) == 'admin') {
  21. return true;
  22. }
  23. return false;
  24. }
  25. public function isReporter($token) {
  26. if($this->getRole($token) == 'reporter') {
  27. return true;
  28. }
  29. return false;
  30. }
  31. public function isConsumer($token) {
  32. if($this->getRole($token) == 'consumer') {
  33. return true;
  34. }
  35. return false;
  36. }
  37. }