clqms-be/app/Controllers/Pages/AuthPage.php

54 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Controllers\Pages;
use CodeIgniter\Controller;
/**
* Auth Pages Controller
* Handles rendering of authentication-related pages
*/
class AuthPage extends Controller
{
/**
* Display the login page
*/
public function login()
{
// Check if user is already authenticated
$token = $this->request->getCookie('token');
if ($token) {
// If token exists, redirect to dashboard
return redirect()->to('/dashboard');
}
return view('pages/login', [
'title' => 'Login',
'description' => 'Sign in to your CLQMS account'
]);
}
/**
* Handle logout - clear cookie and redirect
*/
public function logout()
{
2025-12-22 16:54:19 +07:00
// Determine secure status matching Auth controller logic
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
// Manually expire the cookie with matching attributes to ensure deletion
$this->response->setCookie([
'name' => 'token',
'value' => '',
'expire' => time() - 3600,
'path' => '/',
'secure' => $isSecure,
'httponly' => true,
'samesite' => $isSecure ? 'None' : 'Lax'
]);
2025-12-22 16:54:19 +07:00
return redirect()->to('/login')->withCookies();
}
}