This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/app/lib/App/Core/AccessControl.php

64 lines
1.4 KiB
PHP
Raw Normal View History

2022-01-30 21:11:38 +00:00
<?php
2022-03-02 06:15:12 +00:00
namespace App\Core;
use \Exception;
/**
* TODO: ...
*/
2022-01-30 21:11:38 +00:00
class AccessControl
{
public User $user;
2022-02-07 09:36:00 +00:00
public string $currentPage;
2022-01-30 21:11:38 +00:00
private array $routes;
2022-02-07 09:36:00 +00:00
public function __construct(User $user, string $rootUrl)
2022-01-30 21:11:38 +00:00
{
2022-02-07 09:36:00 +00:00
// FUCK IT, WILL FIX LATER
return;
2022-01-30 21:11:38 +00:00
$this->routes = [
2022-02-07 09:36:00 +00:00
"index.php" => ["catcher", 0],
"example.php",
"simulator.php" => ["catcher", 2],
"login.php",
"logout.php",
"view-teams.php",
"confirm-logout.php",
2022-01-30 21:11:38 +00:00
];
2022-02-07 06:14:33 +00:00
2022-02-07 09:36:00 +00:00
$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?");
2022-01-30 21:11:38 +00:00
}
2022-02-07 09:36:00 +00:00
private function catcher($powerLevel): void
2022-01-30 21:11:38 +00:00
{
2022-02-07 09:36:00 +00:00
if (isset($this->user->powerLevel) && $this->user->powerLevel <= $powerLevel) {
# code...
echo "Authorized!";
} else {
echo "Unauthorized!";
}
2022-01-30 21:11:38 +00:00
}
}