68 lines
2.8 KiB
PHP
68 lines
2.8 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
include 'header.php';
|
|
|
|
$error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($email) || empty($password)) {
|
|
$error = 'Please fill in both fields.';
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$error = 'Please enter a valid email address.';
|
|
} else {
|
|
require_once 'db/config.php';
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email");
|
|
$stmt->execute(['email' => $email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['user_email'] = $user['email'];
|
|
$_SESSION['user_role'] = $user['role'];
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
} else {
|
|
$error = 'Invalid credentials.';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="container flex-grow-1">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 col-lg-5">
|
|
<div class="card shadow-lg border-0 rounded-lg mt-5">
|
|
<div class="card-header text-center bg-primary text-white">
|
|
<h3 class="my-4">Login</h3>
|
|
</div>
|
|
<div class="card-body p-4">
|
|
<p class="text-center text-muted mb-4">Access your IEPR account</p>
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
<form action="login.php" method="POST">
|
|
<div class="form-floating mb-3">
|
|
<input class="form-control" id="inputEmail" type="email" name="email" placeholder="name@example.com" required value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>">
|
|
<label for="inputEmail">Email address</label>
|
|
</div>
|
|
<div class="form-floating mb-3">
|
|
<input class="form-control" id="inputPassword" type="password" name="password" placeholder="Password" required>
|
|
<label for="inputPassword">Password</label>
|
|
</div>
|
|
<div class="d-grid mt-4">
|
|
<button class="btn btn-primary btn-lg" type="submit">Login</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="card-footer text-center py-3">
|
|
<div class="small"><a href="index.php">Back to Home</a></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|