Added filter for check user session and added new routes for the dashboard
This commit is contained in:
parent
833ab2e029
commit
7299f15d60
|
@ -34,6 +34,7 @@ class Filters extends BaseFilters
|
|||
'forcehttps' => ForceHTTPS::class,
|
||||
'pagecache' => PageCache::class,
|
||||
'performance' => PerformanceMetrics::class,
|
||||
'userSession' => \App\Filters\CheckUserSession::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,3 +12,14 @@ $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');
|
||||
$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']);
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
|
||||
/**
|
||||
* Este filtro sirve para comprobar si la sesión aun no se cerro por+
|
||||
* exceder el limite de tiempo, para así evitar errores, sobre todo al guardar datos
|
||||
*/
|
||||
class CheckUserSession implements FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
assert($request instanceof IncomingRequest);
|
||||
$session = session();
|
||||
|
||||
if (!$session->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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue