76 lines
3.1 KiB
PHP
76 lines
3.1 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = htmlspecialchars($_POST['email'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($email) || empty($password)) {
|
|
$error = 'Please enter both email and password.';
|
|
} else {
|
|
try {
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE email = ?");
|
|
$stmt->execute([$email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['user_name'] = $user['name'];
|
|
$_SESSION['user_role'] = $user['role'];
|
|
|
|
header('Location: index.php');
|
|
exit;
|
|
} else {
|
|
$error = 'Invalid email or password.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = 'An error occurred. Please try again later.';
|
|
}
|
|
}
|
|
}
|
|
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<main class="container mt-4" style="min-height: 70vh; display: flex; align-items: center; justify-content: center;">
|
|
<div style="width: 100%; max-width: 450px;">
|
|
<div class="glass-card">
|
|
<h2 class="text-center mb-4">Welcome Back</h2>
|
|
<p class="text-center mb-4" style="color: var(--text-muted);">Login to manage your car listings</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div style="background: rgba(220, 53, 69, 0.2); border: 1px solid #dc3545; color: #dc3545; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
|
|
<?php echo $error; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="login.php">
|
|
<div class="mb-4">
|
|
<label style="display: block; margin-bottom: 8px;">Email Address</label>
|
|
<input type="email" name="email" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
<label style="display: block; margin-bottom: 8px;">Password</label>
|
|
<input type="password" name="password" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary w-100 mb-4">Login</button>
|
|
|
|
<p class="text-center" style="color: var(--text-muted);">
|
|
Don't have an account? <a href="register.php" style="color: var(--accent-gold); text-decoration: none;">Register here</a>
|
|
</p>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="mt-4 text-center">
|
|
<p style="color: var(--text-muted); font-size: 0.8rem;">Admin Demo: admin@gmail.com / 12345678</p>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|