From 677586ded37270b56bd3ae3503af69b021974940 Mon Sep 17 00:00:00 2001 From: Chris Thompson <=> Date: Wed, 16 Oct 2024 22:57:55 +0000 Subject: [PATCH] added Alert that triggers ajax request to extend session if clicked within 5 minutes --- app/config/routes.php | 4 ++- app/src/Controller/SessionsController.php | 25 +++++++++++++ .../layout/TwitterBootstrap/dashboard.php | 15 +++++--- .../layout/TwitterBootstrap/view_record.php | 36 ++++++++++++++++--- app/webroot/js/sessionExtender.js | 15 ++++++++ 5 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 app/src/Controller/SessionsController.php create mode 100644 app/webroot/js/sessionExtender.js diff --git a/app/config/routes.php b/app/config/routes.php index 74f45f5d..2b3d802b 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -82,8 +82,10 @@ * You can remove these routes once you've connected the * routes you want in your application. */ + $builder->fallbacks(); }); + $routes->connect('/keepalive', ['controller' => 'Sessions', 'action' => 'keepalive']); $routes->scope('/images', function ($routes) { $routes->registerMiddleware('glide', new \ADmad\Glide\Middleware\GlideMiddleware([ // Run this middleware only for URLs starting with specified string. Default null. @@ -157,4 +159,4 @@ * }); * ``` */ -}; \ No newline at end of file +}; diff --git a/app/src/Controller/SessionsController.php b/app/src/Controller/SessionsController.php new file mode 100644 index 00000000..ff64cbc8 --- /dev/null +++ b/app/src/Controller/SessionsController.php @@ -0,0 +1,25 @@ +request->getSession(); + // if ($session->check('count')) { + // $session->write(['count' => $session->read('count') + 1]); + // } else { + // $session->write(['count' => 1]); + // } + $response = $this->response; + $response = $response->withStringBody('My Body'); + $response = $response->withType('application/json') + ->withStringBody(json_encode(['response' => 'Session extended'])); + return $response; + } +} diff --git a/app/templates/layout/TwitterBootstrap/dashboard.php b/app/templates/layout/TwitterBootstrap/dashboard.php index aa0eb78d..82a5883f 100644 --- a/app/templates/layout/TwitterBootstrap/dashboard.php +++ b/app/templates/layout/TwitterBootstrap/dashboard.php @@ -22,6 +22,13 @@ ?> fetch("tb_body_attrs") ?>> + Html->script('sessionExtender') + ?> +