<?php
session_start();
if (!empty($_SESSION['admin_logged_in'])) {
header('Location: dashboard.php');
exit;
}
define('BASE_URL', '/eleganceofindia/admin-panal/');
require_once __DIR__ . '/includes/db.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if ($username && $password) {
$stmt = $pdo->prepare('SELECT * FROM admin_users WHERE username = ? LIMIT 1');
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['admin_logged_in'] = true;
$_SESSION['admin_username'] = $user['username'];
header('Location: dashboard.php');
exit;
} else {
$error = 'Invalid username or password.';
}
} else {
$error = 'Please fill in all fields.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Admin Login — Elegance of India</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />
<link rel="stylesheet" href="assets/admin.css" />
</head>
<body>
<div class="login-page">
<div class="login-card">
<div class="login-logo">Elegance of India</div>
<div class="login-sub">Admin Panel</div>
<div class="login-divider"></div>
<?php if ($error): ?>
<div class="alert alert-error"><i class="fas fa-exclamation-circle"></i> <?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST" action="">
<div class="form-group">
<label for="username"><i class="fas fa-user"></i> Username</label>
<input type="text" id="username" name="username" class="form-control"
placeholder="admin" autocomplete="username" value="<?= htmlspecialchars($_POST['username'] ?? '') ?>" required />
</div>
<div class="form-group">
<label for="password"><i class="fas fa-lock"></i> Password</label>
<input type="password" id="password" name="password" class="form-control"
placeholder="••••••••" autocomplete="current-password" required />
</div>
<button type="submit" class="btn btn-gold btn-full" style="margin-top:8px;">
<i class="fas fa-sign-in-alt"></i> Sign In
</button>
</form>
</div>
</div>
</body>
</html>