token.php 825 B

1234567891011121314151617181920212223242526272829303132333435
  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 isClient($token) {
  26. if($this->getRole($token) == 'client') {
  27. return true;
  28. }
  29. return false;
  30. }
  31. }