From 7299f15d60a43ff35cf901196d0aa2c0c932a3d5 Mon Sep 17 00:00:00 2001 From: "Alfonso Saavedra \"Son Link" Date: Thu, 25 Jul 2024 14:48:27 +0200 Subject: [PATCH] Added filter for check user session and added new routes for the dashboard --- app/Config/Filters.php | 1 + app/Config/Routes.php | 13 +++++++++++- app/Filters/CheckUserSession.php | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/Filters/CheckUserSession.php diff --git a/app/Config/Filters.php b/app/Config/Filters.php index eb46a1d..59522ee 100644 --- a/app/Config/Filters.php +++ b/app/Config/Filters.php @@ -34,6 +34,7 @@ class Filters extends BaseFilters 'forcehttps' => ForceHTTPS::class, 'pagecache' => PageCache::class, 'performance' => PerformanceMetrics::class, + 'userSession' => \App\Filters\CheckUserSession::class, ]; /** diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f3d5241..7096152 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -11,4 +11,15 @@ $routes->get('user/(:any)', 'Users::user/$1'); $routes->get('car/(:any)', 'Cars::index/$1'); $routes->get('track/(:any)', 'Tracks::index/$1'); $routes->get('race/(:num)', 'Races::index/$1'); -$routes->get('users', 'Users::index'); \ No newline at end of file +$routes->get('users', 'Users::index'); +$routes->get('login', 'Users::login'); +$routes->post('webserver', 'Webserver::index'); + +$routes->group('dashboard', static function ($routes) { + $routes->get('/', 'Dashboard::index', ['filter' => 'userSession']); + $routes->get('user', 'Dashboard::user', ['filter' => 'userSession']); + $routes->get('logout', 'Dashboard::logout'); + $routes->post('login', 'Dashboard::login'); + $routes->post('update_user', 'Dashboard::updateUser', ['filter' => 'userSession']); + $routes->post('change_passwd', 'Dashboard::changePasswd', ['filter' => 'userSession']); +}); \ No newline at end of file diff --git a/app/Filters/CheckUserSession.php b/app/Filters/CheckUserSession.php new file mode 100644 index 0000000..24e36e2 --- /dev/null +++ b/app/Filters/CheckUserSession.php @@ -0,0 +1,35 @@ +has('userid')) + { + $session->destroy(); + $response = service('response'); + $response->setHeader('Location', base_url('login')); + $response->setStatusCode(302); + + return $response->send(); + } + } + + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) + { + // Do something here + } +} \ No newline at end of file