50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Controllers\Pages;
|
||
|
|
|
||
|
|
use CodeIgniter\Controller;
|
||
|
|
use Firebase\JWT\JWT;
|
||
|
|
use Firebase\JWT\Key;
|
||
|
|
use Firebase\JWT\ExpiredException;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Dashboard Page Controller
|
||
|
|
* Handles rendering of the main dashboard
|
||
|
|
*/
|
||
|
|
class DashboardPage extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Display the dashboard page
|
||
|
|
*/
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
// Check authentication
|
||
|
|
$token = $this->request->getCookie('token');
|
||
|
|
|
||
|
|
if (!$token) {
|
||
|
|
return redirect()->to('/login');
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
$key = getenv('JWT_SECRET');
|
||
|
|
$decoded = JWT::decode($token, new Key($key, 'HS256'));
|
||
|
|
|
||
|
|
return view('pages/dashboard', [
|
||
|
|
'title' => 'Dashboard',
|
||
|
|
'description' => 'CLQMS Dashboard - Overview',
|
||
|
|
'user' => $decoded
|
||
|
|
]);
|
||
|
|
} catch (ExpiredException $e) {
|
||
|
|
// Token expired, redirect to login
|
||
|
|
$response = service('response');
|
||
|
|
$response->deleteCookie('token');
|
||
|
|
return redirect()->to('/login');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
// Invalid token
|
||
|
|
$response = service('response');
|
||
|
|
$response->deleteCookie('token');
|
||
|
|
return redirect()->to('/login');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|