70 lines
2.6 KiB
PHP
70 lines
2.6 KiB
PHP
<?php
|
|
$page_title = "Login - AFG CARS";
|
|
include 'includes/header.php';
|
|
|
|
$error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = trim($_POST['email'] ?? '');
|
|
$password = trim($_POST['password'] ?? '');
|
|
|
|
if ($email && $password) {
|
|
$pdo = db();
|
|
$stmt = $pdo->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_email'] = $user['email'];
|
|
$_SESSION['role'] = $user['role'];
|
|
|
|
if ($user['role'] === 'admin') {
|
|
header('Location: ' . APP_URL . 'admin/dashboard.php');
|
|
} else {
|
|
header('Location: ' . APP_URL . 'user/dashboard.php');
|
|
}
|
|
exit;
|
|
} else {
|
|
$error = "Invalid email or password.";
|
|
}
|
|
} else {
|
|
$error = "Please fill in all fields.";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-5">
|
|
<div class="card border-0 shadow-sm p-4 rounded-4">
|
|
<div class="text-center mb-4">
|
|
<h2 class="fw-bold">Welcome Back</h2>
|
|
<p class="text-muted">Login to AFG CARS Marketplace</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger rounded-3"><?php echo $error; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
<div class="mb-3">
|
|
<label class="form-label small fw-bold">Email Address</label>
|
|
<input type="email" name="email" class="form-control py-2" placeholder="admin@gmail.com" required>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label class="form-label small fw-bold">Password</label>
|
|
<input type="password" name="password" class="form-control py-2" placeholder="••••••••" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100 py-3 rounded-4 fw-bold shadow-sm">Sign In</button>
|
|
</form>
|
|
|
|
<div class="text-center mt-4">
|
|
<p class="text-muted small">Don't have an account? <a href="register.php" class="text-primary fw-bold text-decoration-none">Join Now</a></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|