This commit is contained in:
William 2022-04-13 19:22:21 +00:00
parent 32a2de52f9
commit f3b0baff39
14 changed files with 36 additions and 37 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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 {

View File

@ -1,6 +0,0 @@
<h1>Er du sikker?</h1>
<p>Er du sikker at du vil logge av?</p>
<form action="logout.php">
<button type="submit">Logg ut</button>
</form>

View File

@ -0,0 +1,4 @@
<h1>Er du sikker?</h1>
<p>Er du sikker at du vil logge av?</p>
<span>[&nbsp;<a class="success" href="logout.php?confirm=1">Logg ut</a>&nbsp;]</span>

View File

@ -21,7 +21,7 @@
<?php if ($this->user->loggedIn): ?>
<span><?=htmlspecialchars($this->user->username)?></span>
<a href="<?=$this->config['root_url']?>confirm-logout.php">Logg ut</a>
<a href="<?=$this->config['root_url']?>logout.php">Logg ut</a>
<?php else: ?>
<span>Ikke pålogget</span>
<a href="<?=$this->config['root_url']?>login.php">Logg inn</a>
@ -38,7 +38,7 @@
<h4>Felles</h4>
<ul>
<li><a href="<?=$this->config['root_url']?>index.php">Forside</a></li>
<li><a href="<?=$this->config['root_url']?>race/live-results.php">Resultater</a></li>
<li><a href="<?=$this->config['root_url']?>race/live.php">Resultater</a></li>
</ul>
<?php if ($this->user->loggedIn): ?>
@ -57,7 +57,7 @@
<div id="main">
<?php
// Display flashed messages
// display flashed messages
$msgs = $this->session->getFlashedMessages();
if ($msgs)
{

View File

@ -1,11 +0,0 @@
<?php
$app = require '../app/inc.php';
if (!$app->user->loggedIn)
{
$app->redirect('index.php');
}
$app->view('template/header', ["title" => "Bekreft avlogging"]);
$app->view('pages/confirm-logout');
$app->view('template/footer');

View File

@ -2,7 +2,6 @@
if ($app->user->loggedIn)
{
$app->session->flash('Du er allerede pålogget');
$app->redirect('index.php');
}

View File

@ -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");

View File

@ -1,7 +1,6 @@
<?php $app = require '../../../app/inc.php';
/**
* Resets team counters and removes all time records
* TODO: could be more efficient but who cares
*/
use App\Teamtable\Team;

View File

@ -1,5 +1,5 @@
<?php $app = require '../../app/inc.php';
$app->view('template/header', ["title" => "Live resultater"]);
$app->view('pages/race/live-results');
$app->view('pages/race/live');
$app->view('template/footer');

View File

@ -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)