Create an insecure bank application
This commit is contained in:
40
webroot/lib/Model/Context.php
Normal file
40
webroot/lib/Model/Context.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Model;
|
||||
|
||||
class Context
|
||||
{
|
||||
public ?int $requestTime = null;
|
||||
public ?Session $session = null;
|
||||
public ?string $currentPage = null;
|
||||
public ?array $navigation = null;
|
||||
|
||||
protected function initNavigation()
|
||||
{
|
||||
$this->navigation = [];
|
||||
$this->navigation[] = new NavigationEntry('Startseite', '/');
|
||||
if ($this->session === null) {
|
||||
$this->navigation[] = new NavigationEntry('Registrieren', '/register.php');
|
||||
$this->navigation[] = new NavigationEntry('Einloggen', '/login.php');
|
||||
} else {
|
||||
$this->navigation[] = new NavigationEntry('Umsatzübersicht', '/bookings.php');
|
||||
if ($this->session->user->isAdmin) {
|
||||
$this->navigation[] = new NavigationEntry('Einzahlen', '/deposit.php');
|
||||
$this->navigation[] = new NavigationEntry('Auszahlen', '/withdraw.php');
|
||||
}
|
||||
$this->navigation[] = new NavigationEntry('Überweisen', '/transfer.php');
|
||||
$this->navigation[] = new NavigationEntry('Ausloggen', '/logout.php');
|
||||
}
|
||||
}
|
||||
|
||||
public static function init(string $url): self
|
||||
{
|
||||
$context = new self();
|
||||
$context->requestTime = time();
|
||||
$context->currentPage = $url;
|
||||
$context->session = Session::load();
|
||||
$context->initNavigation();
|
||||
return $context;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user