65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
// login.php
|
|
require_once 'includes/auth.php';
|
|
|
|
if (isLoggedIn()) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (login($email, $password)) {
|
|
if (getUserRole() === 'admin') {
|
|
header("Location: admin/index.php");
|
|
} else {
|
|
header("Location: index.php");
|
|
}
|
|
exit;
|
|
} else {
|
|
$error = "Invalid email or password";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - AFG CARS</title>
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
</head>
|
|
<body style="display: flex; align-items: center; justify-content: center; min-height: 100vh;">
|
|
|
|
<div class="auth-box">
|
|
<h1 class="logo mb-5">AFG CARS</h1>
|
|
<h2 class="mb-5">Login</h2>
|
|
|
|
<?php if ($error): ?>
|
|
<div style="background: rgba(230, 57, 70, 0.2); color: #e63946; padding: 10px; border-radius: 5px; margin-bottom: 20px;">
|
|
<?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
<div class="form-group">
|
|
<input type="email" name="email" class="form-control" placeholder="Email Address" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="password" name="password" class="form-control" placeholder="Password" required>
|
|
</div>
|
|
<button type="submit" class="btn" style="width: 100%;">Sign In</button>
|
|
</form>
|
|
|
|
<p class="mt-5">
|
|
<a href="index.php" style="color: #aaa;">Back to Home</a>
|
|
</p>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|