tlmarker1968

Untitled

Feb 2nd, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. This is my code:
  2.  
  3. /**
  4. * This method check for user authorization to an app
  5. *
  6. * @param AccessCheck $accessCheck - The app and user credentials
  7. *
  8. * @return array user authorization
  9. */
  10. public function CheckAccess(AccessCheck $accessCheck) {
  11. $sql = "SELECT grade, department FROM acl WHERE app=:app";
  12. $stmt = $this->connection->prepare($sql);
  13. $stmt->execute(['app' => $accessCheck->app]);
  14. $access = $stmt->fetch();
  15. var_dump($access);
  16. var_dump($access['grade']);
  17. var_dump((int) $accessCheck->grade - 1);
  18. var_dump(substr($access['grade'], (int) $accessCheck->grade - 1,1));
  19. var_dump(substr($access['department'], (int) $accessCheck->department - 1,1));
  20. if(substr($access['grade'], (int) $accessCheck->grade - 1,1) == "1") {
  21. return "Granted";
  22. } else {
  23. if((substr($access['grade'], (int) $accessCheck->grade - 1, 1) == "1") && (substr($access['department'], (int) $accessCheck->department - 1, 1) == "1")) {
  24. return "Granted";
  25. } else {
  26. return "Denied";
  27. }
  28. }
  29. }
  30.  
  31. This is what postman outputs:
  32.  
  33. C:\Users\tlmar\Documents\GitHub\Phoenix-API\src\Domain\Repository\Security.php:109:
  34. array (size=2)
  35. 'grade' => string '1000' (length=4)
  36. 'department' => string '010000' (length=6)
  37. C:\Users\tlmar\Documents\GitHub\Phoenix-API\src\Domain\Repository\Security.php:110:string '1000' (length=4)
  38. C:\Users\tlmar\Documents\GitHub\Phoenix-API\src\Domain\Repository\Security.php:111:int 0
  39. C:\Users\tlmar\Documents\GitHub\Phoenix-API\src\Domain\Repository\Security.php:112:string '1' (length=1)
  40. C:\Users\tlmar\Documents\GitHub\Phoenix-API\src\Domain\Repository\Security.php:113:string '0' (length=1)
  41. {"success":true,"message":"User Access determined.","data":"Granted"}
  42.  
  43. The grade and department strings are show above. If they are both a 1 I want to return granted, if not it needs to return denied.
Advertisement
Add Comment
Please, Sign In to add comment