Commit
This commit is contained in:
parent
32a2de52f9
commit
f3b0baff39
@ -45,12 +45,6 @@ $app = new App(__DIR__, $config, $database, $session, $user);
|
|||||||
// we will use $app instead
|
// we will use $app instead
|
||||||
unset($config, $database, $session, $user);
|
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);
|
new AccessControl($app);
|
||||||
|
|
||||||
return $app;
|
return $app;
|
@ -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
|
// set headers
|
||||||
http_response_code($status_code);
|
http_response_code($status_code);
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Core;
|
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
|
class Config
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ class Config
|
|||||||
{
|
{
|
||||||
if (!file_exists($path))
|
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;
|
$this->config = require $path;
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Core;
|
namespace App\Core;
|
||||||
|
|
||||||
use \Exception;
|
use \InvalidArgumentException;
|
||||||
use \PDO;
|
use \PDO;
|
||||||
use \PDOException;
|
use \PDOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates a single connection to a database.
|
* Encapsulates a single connection to a database.
|
||||||
* TODO: ...
|
|
||||||
*/
|
*/
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
@ -18,7 +17,7 @@ class Database
|
|||||||
{
|
{
|
||||||
if ($config['name'] !== 'mysql')
|
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 {
|
try {
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
<h1>Er du sikker?</h1>
|
|
||||||
<p>Er du sikker på at du vil logge av?</p>
|
|
||||||
|
|
||||||
<form action="logout.php">
|
|
||||||
<button type="submit">Logg ut</button>
|
|
||||||
</form>
|
|
4
app/view/pages/logout.php
Normal file
4
app/view/pages/logout.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<h1>Er du sikker?</h1>
|
||||||
|
<p>Er du sikker på at du vil logge av?</p>
|
||||||
|
|
||||||
|
<span>[ <a class="success" href="logout.php?confirm=1">Logg ut</a> ]</span>
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<?php if ($this->user->loggedIn): ?>
|
<?php if ($this->user->loggedIn): ?>
|
||||||
<span><?=htmlspecialchars($this->user->username)?></span>
|
<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: ?>
|
<?php else: ?>
|
||||||
<span>Ikke pålogget</span>
|
<span>Ikke pålogget</span>
|
||||||
<a href="<?=$this->config['root_url']?>login.php">Logg inn</a>
|
<a href="<?=$this->config['root_url']?>login.php">Logg inn</a>
|
||||||
@ -38,7 +38,7 @@
|
|||||||
<h4>Felles</h4>
|
<h4>Felles</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="<?=$this->config['root_url']?>index.php">Forside</a></li>
|
<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>
|
</ul>
|
||||||
|
|
||||||
<?php if ($this->user->loggedIn): ?>
|
<?php if ($this->user->loggedIn): ?>
|
||||||
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<?php
|
<?php
|
||||||
// Display flashed messages
|
// display flashed messages
|
||||||
$msgs = $this->session->getFlashedMessages();
|
$msgs = $this->session->getFlashedMessages();
|
||||||
if ($msgs)
|
if ($msgs)
|
||||||
{
|
{
|
||||||
|
@ -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');
|
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
if ($app->user->loggedIn)
|
if ($app->user->loggedIn)
|
||||||
{
|
{
|
||||||
$app->session->flash('Du er allerede pålogget');
|
|
||||||
$app->redirect('index.php');
|
$app->redirect('index.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,16 @@ if (!$app->user->loggedIn)
|
|||||||
$app->redirect('login.php');
|
$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->user->logout();
|
||||||
$app->session->flash('Du har blitt logget av');
|
$app->session->flash('Du har blitt logget av');
|
||||||
$app->redirect("login.php");
|
$app->redirect("login.php");
|
@ -1,7 +1,6 @@
|
|||||||
<?php $app = require '../../../app/inc.php';
|
<?php $app = require '../../../app/inc.php';
|
||||||
/**
|
/**
|
||||||
* Resets team counters and removes all time records
|
* Resets team counters and removes all time records
|
||||||
* TODO: could be more efficient but who cares
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use App\Teamtable\Team;
|
use App\Teamtable\Team;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php $app = require '../../app/inc.php';
|
<?php $app = require '../../app/inc.php';
|
||||||
|
|
||||||
$app->view('template/header', ["title" => "Live resultater"]);
|
$app->view('template/header', ["title" => "Live resultater"]);
|
||||||
$app->view('pages/race/live-results');
|
$app->view('pages/race/live');
|
||||||
$app->view('template/footer');
|
$app->view('template/footer');
|
@ -2,6 +2,9 @@
|
|||||||
/**
|
/**
|
||||||
* We originally wanted to use SSE for this, but the hosting provider
|
* We originally wanted to use SSE for this, but the hosting provider
|
||||||
* did not support that so we resorted to simple polling instead
|
* 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;
|
use App\Teamtable\TeamMapper;
|
||||||
@ -32,6 +35,14 @@ foreach ($times as $time)
|
|||||||
array_push($data, $row);
|
array_push($data, $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$hash = crc32(serialize($data));
|
$hash = crc32(serialize($data));
|
||||||
|
|
||||||
if ($prev_hash !== $hash)
|
if ($prev_hash !== $hash)
|
||||||
|
Reference in New Issue
Block a user