This commit is contained in:
William 2022-02-07 10:36:00 +01:00
parent 7cd3213f6e
commit 3df898e5bb

View File

@ -1,24 +1,58 @@
<?php
// TODO: ...
class AccessControl
{
public User $user;
public string $currentPage;
private array $routes;
public function __construct(User $user)
public function __construct(User $user, string $rootUrl)
{
$this->user = $user;
// FUCK IT, WILL FIX LATER
return;
$this->routes = [
"index.php" => ["catcher", 0]
"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));
call_user_func_array([$this, "catcher"], [0]);
// FUCK IT, WILL FIX LATER
return;
foreach ($this->routes as $key => $value)
{
if ($key !== $this->currentPage)
{
continue;
}
private function catcher($level): void
if ($value)
{
echo "hello $level";
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!";
}
}
}