87 lines
4.1 KiB
PHP
87 lines
4.1 KiB
PHP
<?php
|
|
$title = "Register";
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$full_name = $_POST['full_name'] ?? '';
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
$confirm_password = $_POST['confirm_password'] ?? '';
|
|
|
|
if (empty($full_name) || empty($email) || empty($password) || empty($confirm_password)) {
|
|
$error = "Please fill in all fields.";
|
|
} elseif ($password !== $confirm_password) {
|
|
$error = "Passwords do not match.";
|
|
} elseif (strlen($password) < 8) {
|
|
$error = "Password must be at least 8 characters long.";
|
|
} else {
|
|
$db = db();
|
|
$checkStmt = $db->prepare("SELECT id FROM users WHERE email = ? LIMIT 1");
|
|
$checkStmt->execute([$email]);
|
|
if ($checkStmt->fetch()) {
|
|
$error = "Email address is already registered.";
|
|
} else {
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
$stmt = $db->prepare("INSERT INTO users (full_name, email, password, role) VALUES (?, ?, ?, 'USER')");
|
|
if ($stmt->execute([$full_name, $email, $hashed_password])) {
|
|
header("Location: login.php?msg=" . urlencode("Registration successful! Please login."));
|
|
exit;
|
|
} else {
|
|
$error = "Registration failed. Please try again.";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<section class="hero">
|
|
<div class="container">
|
|
<div class="glass-card" style="max-width: 600px; margin: 0 auto; padding: 4rem; text-align: left;">
|
|
<h2 style="margin-bottom: 0.75rem; text-align: center;" class="text-gradient">Join the Elite</h2>
|
|
<p style="color: var(--text-muted); text-align: center; margin-bottom: 3.5rem;">Create your AFG CARS account</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div style="background: rgba(239, 68, 68, 0.1); border: 1px solid var(--danger); color: var(--danger); padding: 1.25rem; border-radius: var(--radius-md); margin-bottom: 2rem; font-size: 0.9rem; text-align: center;">
|
|
<?php echo $error; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="register.php" method="POST">
|
|
<div class="form-group">
|
|
<label>Full Name</label>
|
|
<input type="text" name="full_name" class="form-control" placeholder="Enter your full name" value="<?php echo htmlspecialchars($full_name ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Email Address</label>
|
|
<input type="email" name="email" class="form-control" placeholder="Enter your email" value="<?php echo htmlspecialchars($email ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;">
|
|
<div class="form-group">
|
|
<label>Password</label>
|
|
<input type="password" name="password" class="form-control" placeholder="Min. 8 characters" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Confirm Password</label>
|
|
<input type="password" name="confirm_password" class="form-control" placeholder="Repeat password" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="margin-top: 2rem;">
|
|
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 1.25rem; font-size: 1.1rem;">Create Account</button>
|
|
</div>
|
|
|
|
<div style="margin-top: 3rem; text-align: center; color: var(--text-muted); font-size: 0.95rem;">
|
|
Already have an account? <a href="login.php" style="color: var(--primary); font-weight: 700;">Login now</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|