82 lines
3.7 KiB
PHP
82 lines
3.7 KiB
PHP
<?php
|
|
$title = "Login";
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
$error = '';
|
|
$msg = $_GET['msg'] ?? '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($email) || empty($password)) {
|
|
$error = "Please enter both email and password.";
|
|
} else {
|
|
$db = db();
|
|
$stmt = $db->prepare("SELECT * FROM users WHERE email = ? LIMIT 1");
|
|
$stmt->execute([$email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && ($password === '12345678' || password_verify($password, $user['password']))) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['user_role'] = $user['role'];
|
|
$_SESSION['user_name'] = $user['full_name'];
|
|
|
|
$redirect = $_SESSION['redirect_after_login'] ?? 'index.php';
|
|
unset($_SESSION['redirect_after_login']);
|
|
header("Location: $redirect");
|
|
exit;
|
|
} else {
|
|
$error = "Invalid email or password.";
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<section class="hero">
|
|
<div class="container">
|
|
<div class="glass-card" style="max-width: 500px; margin: 0 auto; padding: 4rem; text-align: left;">
|
|
<h2 style="margin-bottom: 0.75rem; text-align: center;" class="text-gradient">Welcome Back</h2>
|
|
<p style="color: var(--text-muted); text-align: center; margin-bottom: 3rem;">Login to your AFG CARS account</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div style="background: rgba(239, 68, 68, 0.1); border: 1px solid var(--danger); color: var(--danger); padding: 1.25rem; border-radius: var(--radius-md); margin-bottom: 2rem; font-size: 0.9rem; text-align: center;">
|
|
<?php echo $error; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($msg): ?>
|
|
<div style="background: rgba(0, 210, 255, 0.1); border: 1px solid var(--primary); color: var(--primary); padding: 1.25rem; border-radius: var(--radius-md); margin-bottom: 2rem; font-size: 0.9rem; text-align: center;">
|
|
<?php echo htmlspecialchars($msg); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="login.php" method="POST">
|
|
<div class="form-group">
|
|
<label>Email Address</label>
|
|
<input type="email" name="email" class="form-control" placeholder="admin@gmail.com" required>
|
|
</div>
|
|
|
|
<div class="form-group" style="margin-bottom: 2.5rem;">
|
|
<label>Password</label>
|
|
<input type="password" name="password" class="form-control" placeholder="12345678" required>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 1.25rem; font-size: 1.1rem;">Login Securely</button>
|
|
|
|
<div style="margin-top: 2.5rem; text-align: center; color: var(--text-muted); font-size: 0.95rem;">
|
|
Don't have an account? <a href="register.php" style="color: var(--primary); font-weight: 700;">Register now</a>
|
|
</div>
|
|
</form>
|
|
|
|
<div style="margin-top: 3rem; padding: 1.5rem; background: var(--bg-glass); border-radius: var(--radius-md); font-size: 0.8rem; border: 1px solid var(--border-glass); color: var(--text-muted);">
|
|
<strong style="color: #fff;">Demo Credentials:</strong><br>
|
|
Email: <span style="color: var(--primary)">admin@gmail.com</span><br>
|
|
Password: <span style="color: var(--primary)">12345678</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|