114 lines
5.7 KiB
PHP
114 lines
5.7 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$project_name = $_SERVER['PROJECT_NAME'] ?? 'LPA Online';
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
$accept_terms = isset($_POST['accept_terms']);
|
|
|
|
if (empty($email) || empty($password)) {
|
|
$error = 'Please enter both email and password.';
|
|
} elseif (!$accept_terms) {
|
|
$error = 'You must accept the Terms & Conditions to log in.';
|
|
} else {
|
|
$stmt = db()->prepare('SELECT * FROM users WHERE email = ?');
|
|
$stmt->execute([$email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
if ($user['is_verified'] == 0) {
|
|
$error = 'Please verify your email address before logging in. Check your inbox for the verification link. ' .
|
|
'<a href="resend-verification.php?email=' . urlencode($email) . '" class="text-primary text-decoration-underline fw-semibold small">Resend link?</a>';
|
|
} else {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['user_email'] = $user['email'];
|
|
$_SESSION['user_name'] = $user['name'] ?? 'User';
|
|
$_SESSION['user_role'] = $user['role'] ?? 'Standard User';
|
|
|
|
if ($_SESSION['user_role'] === 'Super User') {
|
|
header('Location: admin_dashboard.php');
|
|
} else {
|
|
header('Location: apply.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 — <?php echo htmlspecialchars($project_name); ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css" rel="stylesheet">
|
|
</head>
|
|
<body class="bg-light d-flex flex-column min-vh-100">
|
|
<nav class="navbar navbar-expand-lg bg-white border-bottom shadow-sm">
|
|
<div class="container justify-content-center">
|
|
<a class="navbar-brand d-flex align-items-center m-0" href="/">
|
|
<img src="assets/pasted-20260228-235417-eedda424.png" alt="<?php echo htmlspecialchars($project_name); ?>" height="40">
|
|
</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container py-5 flex-grow-1 d-flex align-items-center">
|
|
<div class="row justify-content-center w-100 m-0">
|
|
<div class="col-md-5 col-lg-4">
|
|
<div class="card shadow-lg border-0 p-4 p-md-5 rounded-4">
|
|
<div class="text-center mb-4">
|
|
<h1 class="h3 fw-bold">Welcome back</h1>
|
|
<p class="text-muted small">Please enter your details to sign in.</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger small py-2"><?php echo $error; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form action="login.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label small fw-bold">Email Address</label>
|
|
<input type="email" class="form-control form-control-lg" id="email" name="email" placeholder="name@company.com" required value="<?php echo htmlspecialchars($_POST['email'] ?? ''); ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<label for="password" class="form-label small fw-bold mb-0">Password</label>
|
|
<a href="forgot-password.php" class="small text-primary text-decoration-none fw-semibold">Forgot Password?</a>
|
|
</div>
|
|
<input type="password" class="form-control form-control-lg mt-2" id="password" name="password" placeholder="••••••••" required>
|
|
</div>
|
|
<div class="mb-4">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="accept_terms" name="accept_terms" required>
|
|
<label class="form-check-label small text-secondary" for="accept_terms">
|
|
I accept the <a href="terms.php" class="text-primary text-decoration-none fw-semibold">Terms & Conditions</a>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary btn-lg w-100 rounded-pill">Sign In</button>
|
|
</form>
|
|
|
|
<div class="text-center mt-4 pt-2 border-top">
|
|
<p class="text-muted small mb-1">Don't have an account? <a href="signup.php" class="text-primary text-decoration-none fw-semibold">Sign Up</a></p>
|
|
<p class="text-muted small mb-0">Didn't receive activation email? <a href="resend-verification.php" class="text-primary text-decoration-none fw-semibold">Resend link</a></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="py-4 text-center text-muted">
|
|
<div class="container">
|
|
<p class="small mb-0">© <?php echo date('Y'); ?> <?php echo htmlspecialchars($project_name); ?>. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|