55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
include 'header.php';
|
|
|
|
$error_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (empty($_POST['email']) || empty($_POST['password'])) {
|
|
$error_message = 'Please enter both email and password.';
|
|
} else {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM customers WHERE email = ?");
|
|
$stmt->execute([$_POST['email']]);
|
|
$customer = $stmt->fetch();
|
|
|
|
if ($customer && password_verify($_POST['password'], $customer['password'])) {
|
|
$_SESSION['customer_id'] = $customer['id'];
|
|
$_SESSION['customer_name'] = $customer['name'];
|
|
header('Location: portal.php');
|
|
exit;
|
|
} else {
|
|
$error_message = 'Invalid email or password.';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h1 class="card-title text-center mb-4">Customer Login</h1>
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
|
<?php endif; ?>
|
|
<form method="POST" action="login.php">
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email Address</label>
|
|
<input type="email" id="email" name="email" class="form-control" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label">Password</label>
|
|
<input type="password" id="password" name="password" class="form-control" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100">Login</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|