58 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| // TODO: ...
 | |
| class AccessControl
 | |
| {
 | |
|     public User $user;
 | |
|     public string $currentPage;
 | |
|     private array $routes;
 | |
| 
 | |
|     public function __construct(User $user, string $rootUrl)
 | |
|     {
 | |
|         // FUCK IT, WILL FIX LATER
 | |
|         return;
 | |
| 
 | |
|         $this->routes = [
 | |
|             "index.php"     => ["catcher", 0],
 | |
|             "example.php",
 | |
|             "simulator.php" => ["catcher", 2],
 | |
|             "login.php",
 | |
|             "logout.php",
 | |
|             "view-teams.php",
 | |
|             "confirm-logout.php",
 | |
|         ];
 | |
| 
 | |
|         $this->user = $user;
 | |
|         $this->currentPage = substr($_SERVER["PHP_SELF"], strlen($rootUrl));
 | |
| 
 | |
|         // FUCK IT, WILL FIX LATER
 | |
|         return;
 | |
| 
 | |
|         foreach ($this->routes as $key => $value)
 | |
|         {
 | |
|             if ($key !== $this->currentPage)
 | |
|             {
 | |
|                 continue;
 | |
|             }
 | |
| 
 | |
|             if ($value)
 | |
|             {
 | |
|                 call_user_func([$this, $value[0]], $value[1]);
 | |
|             }
 | |
| 
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         throw new Exception("Could not find current page in access control routes array, did you add it?");
 | |
|     }
 | |
| 
 | |
|     private function catcher($powerLevel): void
 | |
|     {
 | |
|         if (isset($this->user->powerLevel) && $this->user->powerLevel <= $powerLevel) {
 | |
|             # code...
 | |
|             echo "Authorized!";
 | |
|         } else {
 | |
|             echo "Unauthorized!";
 | |
|         }
 | |
|     }
 | |
| } |