diff --git a/app/inc.php b/app/inc.php index 6c28c74..84eda46 100644 --- a/app/inc.php +++ b/app/inc.php @@ -45,12 +45,6 @@ $app = new App(__DIR__, $config, $database, $session, $user); // we will use $app instead unset($config, $database, $session, $user); -/** - * This is important! - * Without it, everyone will have access to any page without having to be logged in. - * - * Decides if the user is allowed to view current page. - */ new AccessControl($app); return $app; \ No newline at end of file diff --git a/app/lib/App/Core/App.php b/app/lib/App/Core/App.php index 2cb8820..87cc510 100644 --- a/app/lib/App/Core/App.php +++ b/app/lib/App/Core/App.php @@ -70,9 +70,9 @@ class App } /** - * Turn data array into json response + * Convert data into json response */ - public function api($data, int $status_code = 200): void + public function api(mixed $data, int $status_code = 200): void { // set headers http_response_code($status_code); diff --git a/app/lib/App/Core/Config.php b/app/lib/App/Core/Config.php index 0fda980..584673a 100644 --- a/app/lib/App/Core/Config.php +++ b/app/lib/App/Core/Config.php @@ -2,10 +2,10 @@ namespace App\Core; -use \Exception; +use \InvalidArgumentException; /** - * TODO: ... this should validate the config and stuffs + * TODO: this should validate the config and stuffs */ class Config { @@ -18,7 +18,7 @@ class Config { if (!file_exists($path)) { - throw new Exception("Could not find configuration file: $path"); + throw new InvalidArgumentException("Could not find configuration file: $path"); } $this->config = require $path; } diff --git a/app/lib/App/Core/Database.php b/app/lib/App/Core/Database.php index 224ac35..d63de1a 100644 --- a/app/lib/App/Core/Database.php +++ b/app/lib/App/Core/Database.php @@ -2,13 +2,12 @@ namespace App\Core; -use \Exception; +use \InvalidArgumentException; use \PDO; use \PDOException; /** * Encapsulates a single connection to a database. - * TODO: ... */ class Database { @@ -18,7 +17,7 @@ class Database { if ($config['name'] !== 'mysql') { - throw new Exception("Database error: ".$config['name']." is not implemented"); + throw new InvalidArgumentException("Database error: driver ".$config['name']." is not implemented"); } try { diff --git a/app/view/pages/confirm-logout.php b/app/view/pages/confirm-logout.php deleted file mode 100644 index 1a695cd..0000000 --- a/app/view/pages/confirm-logout.php +++ /dev/null @@ -1,6 +0,0 @@ -

Er du sikker?

-

Er du sikker på at du vil logge av?

- -
- -
\ No newline at end of file diff --git a/app/view/pages/logout.php b/app/view/pages/logout.php new file mode 100644 index 0000000..5b0f790 --- /dev/null +++ b/app/view/pages/logout.php @@ -0,0 +1,4 @@ +

Er du sikker?

+

Er du sikker på at du vil logge av?

+ +Logg ut ] \ No newline at end of file diff --git a/app/view/pages/race/live-results.php b/app/view/pages/race/live.php similarity index 100% rename from app/view/pages/race/live-results.php rename to app/view/pages/race/live.php diff --git a/app/view/template/header.php b/app/view/template/header.php index 83f24b8..21b6c79 100644 --- a/app/view/template/header.php +++ b/app/view/template/header.php @@ -21,7 +21,7 @@ user->loggedIn): ?> user->username)?> - Logg ut + Logg ut Ikke pålogget Logg inn @@ -38,7 +38,7 @@

Felles

user->loggedIn): ?> @@ -57,7 +57,7 @@
session->getFlashedMessages(); if ($msgs) { diff --git a/public/confirm-logout.php b/public/confirm-logout.php deleted file mode 100644 index 6fdb66a..0000000 --- a/public/confirm-logout.php +++ /dev/null @@ -1,11 +0,0 @@ -user->loggedIn) -{ - $app->redirect('index.php'); -} - -$app->view('template/header', ["title" => "Bekreft avlogging"]); -$app->view('pages/confirm-logout'); -$app->view('template/footer'); \ No newline at end of file diff --git a/public/login.php b/public/login.php index 11b1e08..5512cd8 100644 --- a/public/login.php +++ b/public/login.php @@ -2,7 +2,6 @@ if ($app->user->loggedIn) { - $app->session->flash('Du er allerede pålogget'); $app->redirect('index.php'); } diff --git a/public/logout.php b/public/logout.php index 76656e4..bbc15f1 100644 --- a/public/logout.php +++ b/public/logout.php @@ -6,6 +6,16 @@ if (!$app->user->loggedIn) $app->redirect('login.php'); } +$confirm = filter_input(INPUT_GET, 'confirm', FILTER_VALIDATE_BOOLEAN); + +if (!$confirm) +{ + $app->view('template/header', ["title" => "Bekreft avlogging"]); + $app->view('pages/logout'); + $app->view('template/footer'); + die(); +} + $app->user->logout(); $app->session->flash('Du har blitt logget av'); $app->redirect("login.php"); \ No newline at end of file diff --git a/public/race/configure/reset.php b/public/race/configure/reset.php index 091b007..0fe7849 100644 --- a/public/race/configure/reset.php +++ b/public/race/configure/reset.php @@ -1,7 +1,6 @@ view('template/header', ["title" => "Live resultater"]); -$app->view('pages/race/live-results'); +$app->view('pages/race/live'); $app->view('template/footer'); \ No newline at end of file diff --git a/public/race/sync.php b/public/race/sync.php index ca6644a..66a22b0 100644 --- a/public/race/sync.php +++ b/public/race/sync.php @@ -2,6 +2,9 @@ /** * We originally wanted to use SSE for this, but the hosting provider * did not support that so we resorted to simple polling instead + * + * This page compiles a set of data and sends it if the provided hash of + * the data is not equal. */ use App\Teamtable\TeamMapper; @@ -32,6 +35,14 @@ foreach ($times as $time) array_push($data, $row); } + + + + + + + + $hash = crc32(serialize($data)); if ($prev_hash !== $hash)