Commit
This commit is contained in:
parent
7cd3213f6e
commit
3df898e5bb
@ -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;
|
||||
}
|
||||
|
||||
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($level): void
|
||||
private function catcher($powerLevel): void
|
||||
{
|
||||
echo "hello $level";
|
||||
if (isset($this->user->powerLevel) && $this->user->powerLevel <= $powerLevel) {
|
||||
# code...
|
||||
echo "Authorized!";
|
||||
} else {
|
||||
echo "Unauthorized!";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user