54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?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()
|
|
{
|
|
// 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'
|
|
]);
|
|
|
|
return redirect()->to('/login')->withCookies();
|
|
}
|
|
}
|