Implement toggle in main controller.
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
<?php
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
if (\FooBar\Configuration::loadConfig()->isOpen()) {
|
||||
$config = \FooBar\Configuration::loadConfig();
|
||||
|
||||
if (isset($_POST['auth_check'])) {
|
||||
if (!$config->isAuthorized()) {
|
||||
http_response_code(403);
|
||||
}
|
||||
} elseif (isset($_POST['toggle']) && $config->isAuthorized()) {
|
||||
$file = $config->stateFile();
|
||||
if ($config->isOpen()) {
|
||||
unlink($file);
|
||||
} else {
|
||||
touch($file);
|
||||
}
|
||||
}
|
||||
|
||||
if ($config->isOpen()) {
|
||||
require '../templates/open.html';
|
||||
} else {
|
||||
require '../templates/closed.html';
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
$configuration = \FooBar\Configuration::loadConfig();
|
||||
|
||||
if (isset($_POST['toggle']) && $configuration->isAuthorized()) {
|
||||
$file = $configuration->stateFile();
|
||||
if ($configuration->isOpen()) {
|
||||
unlink($file);
|
||||
} else {
|
||||
touch($file);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Verander de status van de foobar</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>De foobar is nu
|
||||
<?php
|
||||
echo $configuration->isOpen() ? ' ' : ' niet ';
|
||||
?>
|
||||
open.</h1>
|
||||
<form method="post">
|
||||
<input type="submit" name="toggle" value="Verander dit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user