auth.php 1.1 KB

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