84 lines
3.1 KiB
PHP
84 lines
3.1 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// --- Configuration ---
|
|
// IMPORTANT: These are hardcoded for demonstration purposes.
|
|
// In a real-world application, use a secure way to store and manage credentials.
|
|
$admin_credentials = require __DIR__ . '/config/admin_credentials.php';
|
|
define('ADMIN_USERNAME', $admin_credentials['username']);
|
|
define('ADMIN_PASSWORD', $admin_credentials['password']);
|
|
|
|
$error_message = null;
|
|
$is_logged_in = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
|
|
|
// --- Logout Logic ---
|
|
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
|
|
session_unset();
|
|
session_destroy();
|
|
header('Location: admin.php');
|
|
exit;
|
|
}
|
|
|
|
// --- Login Logic ---
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username']) && isset($_POST['password'])) {
|
|
if ($_POST['username'] === ADMIN_USERNAME && $_POST['password'] === ADMIN_PASSWORD) {
|
|
$_SESSION['isAdmin'] = true;
|
|
header('Location: admin.php');
|
|
exit;
|
|
} else {
|
|
$error_message = "Invalid username or password.";
|
|
}
|
|
}
|
|
|
|
// --- Page Setup ---
|
|
$page_title = $is_logged_in ? "Admin Dashboard" : "Admin Login";
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo htmlspecialchars($page_title); ?> - SecureLife</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<header class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">SecureLife</a>
|
|
<?php if ($is_logged_in): ?>
|
|
<ul class="navbar-nav">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="admin.php?action=logout">Logout</a>
|
|
</li>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container my-5">
|
|
<?php
|
|
if ($is_logged_in) {
|
|
include 'partials/admin_dashboard.php';
|
|
} else {
|
|
// Pass the error message to the login form
|
|
include 'partials/admin_login.php';
|
|
}
|
|
?>
|
|
</main>
|
|
|
|
<footer class="text-center py-4 mt-auto bg-dark text-white">
|
|
<p class="mb-0">© <?php echo date("Y"); ?> SecureLife. All Rights Reserved.</p>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|