auth.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. $data = false;
  3. function getBannedUsers($string){
  4. if (strpos($string, ',') !== false) {
  5. $banned = explode(",", $string);
  6. }elseif (strpos($string, ',') == false) {
  7. $banned = array($string);
  8. }
  9. return $banned;
  10. }
  11. if (isset($_GET['ban'])) : $ban = strtoupper($_GET['ban']); else : $ban = ""; endif;
  12. require_once("user.php");
  13. $USER = new User("registration_callback");
  14. if (isset($_GET['admin'])) :
  15. if($USER->authenticated && $USER->role == "admin" && !in_array(strtoupper($USER->username), getBannedUsers($ban))) :
  16. exit(http_response_code(200));
  17. else :
  18. exit(http_response_code(401));
  19. endif;
  20. elseif (isset($_GET['user'])) :
  21. if($USER->authenticated && !in_array(strtoupper($USER->username), getBannedUsers($ban))) :
  22. exit(http_response_code(200));
  23. else :
  24. exit(http_response_code(401));
  25. endif;
  26. elseif (!isset($_GET['user']) && !isset($_GET['admin'])) :
  27. exit(http_response_code(401));
  28. endif;
  29. ?>