summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2021-10-18 21:15:18 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2021-10-18 21:15:18 +0100
commit1a112ab14becaf6d41cd34c176cbe563d4ca9742 (patch)
treeaad7dd85d9a7d3d4465a6ef506a0259b46ed6ee7 /public
parentcbaedbc5251f3b127bd81242d1344c0cd3e56e0c (diff)
Implement session management
Diffstat (limited to 'public')
-rw-r--r--public/delete/index.php5
-rw-r--r--public/index.php10
-rw-r--r--public/store/index.php7
-rw-r--r--public/update/index.php5
4 files changed, 25 insertions, 2 deletions
diff --git a/public/delete/index.php b/public/delete/index.php
index e07129a..9864c9a 100644
--- a/public/delete/index.php
+++ b/public/delete/index.php
@@ -3,6 +3,7 @@
declare(strict_types=1);
use DTS\BookmarkRepository;
+use DTS\Session;
use function DTS\Functions\respondAndExit;
use function DTS\Functions\redirectAndExit;
@@ -10,6 +11,8 @@ require_once(__DIR__.'/../../autoload.php');
$config = require_once(__DIR__.'/../../config.php');
+$session = Session::getInstance();
+
if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') {
respondAndExit(405, 'Method Not Allowed');
}
@@ -28,4 +31,6 @@ if (!$bookmarks->delete($bookmark)) {
respondAndExit(500, 'Internal Server Error');
}
+$session->set('message', 'Bookmark Deleted');
+
redirectAndExit('/');
diff --git a/public/index.php b/public/index.php
index 7453506..025c9ec 100644
--- a/public/index.php
+++ b/public/index.php
@@ -3,6 +3,7 @@
declare(strict_types=1);
use DTS\BookmarkRepository;
+use DTS\Session;
use DTS\Template;
use function DTS\Functions\respondAndExit;
@@ -10,6 +11,8 @@ require_once(__DIR__.'/../autoload.php');
$config = require_once(__DIR__.'/../config.php');
+$session = Session::getInstance();
+
$bookmarks = new BookmarkRepository($config['path_to_repository']);
$template = new Template($config['path_to_templates']);
@@ -24,6 +27,11 @@ if ($tag !== null) {
$bookmarks->sort($sort === 'asc');
-$html = $template->render('index', compact('bookmarks'));
+$message = $session->get('message');
+
+$html = $template->render('index', compact(
+ 'bookmarks',
+ 'message'
+));
respondAndExit(200, 'OK', $html);
diff --git a/public/store/index.php b/public/store/index.php
index 2a84c59..45765d5 100644
--- a/public/store/index.php
+++ b/public/store/index.php
@@ -4,13 +4,16 @@ declare(strict_types=1);
use DTS\Bookmark;
use DTS\BookmarkRepository;
-use function DTS\Functions\respondAndExit;
+use DTS\Session;
use function DTS\Functions\redirectAndExit;
+use function DTS\Functions\respondAndExit;
require_once(__DIR__.'/../../autoload.php');
$config = require_once(__DIR__.'/../../config.php');
+$session = Session::getInstance();
+
if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') {
respondAndExit(405, 'Method Not Allowed');
}
@@ -30,4 +33,6 @@ if (!$bookmarks->add($bookmark)) {
respondAndExit(500, 'Internal Server Error');
}
+$session->set('message', 'Bookmark Added');
+
redirectAndExit('/');
diff --git a/public/update/index.php b/public/update/index.php
index fa6b482..50d0dcf 100644
--- a/public/update/index.php
+++ b/public/update/index.php
@@ -3,6 +3,7 @@
declare(strict_types=1);
use DTS\BookmarkRepository;
+use DTS\Session;
use function DTS\Functions\respondAndExit;
use function DTS\Functions\redirectAndExit;
@@ -10,6 +11,8 @@ require_once(__DIR__.'/../../autoload.php');
$config = require_once(__DIR__.'/../../config.php');
+$session = Session::getInstance();
+
if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') {
respondAndExit(405, 'Method Not Allowed');
}
@@ -32,4 +35,6 @@ if (!$bookmarks->update($bookmark)) {
respondAndExit(500, 'Internal Server Error');
}
+$session->set('message', 'Bookmark Updated');
+
redirectAndExit('/');