This commit is contained in:
Flatlogic Bot 2026-02-16 05:06:25 +00:00
parent c7120bdcbd
commit f65de53240
3 changed files with 261 additions and 0 deletions

94
contact.php Normal file
View File

@ -0,0 +1,94 @@
<?php
require_once 'db/config.php';
require_once 'mail/MailService.php';
$success = '';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = htmlspecialchars($_POST['name'] ?? '');
$email = htmlspecialchars($_POST['email'] ?? '');
$subject = htmlspecialchars($_POST['subject'] ?? '');
$message = htmlspecialchars($_POST['message'] ?? '');
if (empty($name) || empty($email) || empty($message)) {
$error = 'Please fill in all required fields.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Please enter a valid email address.';
} else {
try {
$stmt = db()->prepare("INSERT INTO contact_messages (name, email, subject, message) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $email, $subject, $message]);
// Send email using MailService
$res = MailService::sendContactMessage($name, $email, $message);
$success = 'Thank you for your message! We will get back to you soon.';
} catch (PDOException $e) {
$error = 'An error occurred while sending your message. Please try again later.';
}
}
}
include 'includes/header.php';
?>
<main class="container mt-4">
<div class="row justify-between align-center">
<div class="col-6">
<h1 class="section-title">Get in Touch</h1>
<p class="mb-4" style="color: var(--text-muted);">Have questions about a car or want to list your own? Our team in Kabul is ready to help you 24/7.</p>
<div class="glass-card mb-4">
<h3 class="text-gold mb-4">Contact Information</h3>
<p><strong>Email:</strong> admin@gmail.com</p>
<p><strong>Location:</strong> Kabul, Afghanistan</p>
<p><strong>Developer:</strong> Mohammad Sadiq</p>
</div>
</div>
<div class="col-6">
<div class="glass-card">
<h2 class="mb-4">Send a Message</h2>
<?php if ($success): ?>
<div style="background: rgba(40, 167, 69, 0.2); border: 1px solid #28a745; color: #28a745; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
<?php echo $success; ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div style="background: rgba(220, 53, 69, 0.2); border: 1px solid #dc3545; color: #dc3545; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
<?php echo $error; ?>
</div>
<?php endif; ?>
<form method="POST" action="contact.php">
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Full Name *</label>
<input type="text" name="name" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Email Address *</label>
<input type="email" name="email" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Subject</label>
<input type="text" name="subject" style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Message *</label>
<textarea name="message" rows="5" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;"></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">Send Message</button>
</form>
</div>
</div>
</div>
</main>
<?php include 'includes/footer.php'; ?>

75
login.php Normal file
View File

@ -0,0 +1,75 @@
<?php
session_start();
require_once 'db/config.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = htmlspecialchars($_POST['email'] ?? '');
$password = $_POST['password'] ?? '';
if (empty($email) || empty($password)) {
$error = 'Please enter both email and password.';
} else {
try {
$stmt = db()->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_role'] = $user['role'];
header('Location: index.php');
exit;
} else {
$error = 'Invalid email or password.';
}
} catch (PDOException $e) {
$error = 'An error occurred. Please try again later.';
}
}
}
include 'includes/header.php';
?>
<main class="container mt-4" style="min-height: 70vh; display: flex; align-items: center; justify-content: center;">
<div style="width: 100%; max-width: 450px;">
<div class="glass-card">
<h2 class="text-center mb-4">Welcome Back</h2>
<p class="text-center mb-4" style="color: var(--text-muted);">Login to manage your car listings</p>
<?php if ($error): ?>
<div style="background: rgba(220, 53, 69, 0.2); border: 1px solid #dc3545; color: #dc3545; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
<?php echo $error; ?>
</div>
<?php endif; ?>
<form method="POST" action="login.php">
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Email Address</label>
<input type="email" name="email" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Password</label>
<input type="password" name="password" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<button type="submit" class="btn btn-primary w-100 mb-4">Login</button>
<p class="text-center" style="color: var(--text-muted);">
Don't have an account? <a href="register.php" style="color: var(--accent-gold); text-decoration: none;">Register here</a>
</p>
</form>
</div>
<div class="mt-4 text-center">
<p style="color: var(--text-muted); font-size: 0.8rem;">Admin Demo: admin@gmail.com / 12345678</p>
</div>
</div>
</main>
<?php include 'includes/footer.php'; ?>

92
register.php Normal file
View File

@ -0,0 +1,92 @@
<?php
session_start();
require_once 'db/config.php';
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = htmlspecialchars($_POST['name'] ?? '');
$email = htmlspecialchars($_POST['email'] ?? '');
$password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
if (empty($name) || empty($email) || empty($password)) {
$error = 'Please fill in all required fields.';
} elseif ($password !== $confirm_password) {
$error = 'Passwords do not match.';
} elseif (strlen($password) < 8) {
$error = 'Password must be at least 8 characters long.';
} else {
try {
// Check if email already exists
$stmt = db()->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$error = 'This email is already registered.';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = db()->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
$stmt->execute([$name, $email, $hashed_password]);
$success = 'Account created successfully! You can now <a href="login.php" style="color: var(--accent-gold);">login</a>.';
}
} catch (PDOException $e) {
$error = 'An error occurred. Please try again later.';
}
}
}
include 'includes/header.php';
?>
<main class="container mt-4" style="min-height: 70vh; display: flex; align-items: center; justify-content: center;">
<div style="width: 100%; max-width: 450px;">
<div class="glass-card">
<h2 class="text-center mb-4">Create Account</h2>
<p class="text-center mb-4" style="color: var(--text-muted);">Join the premium car marketplace in Afghanistan</p>
<?php if ($error): ?>
<div style="background: rgba(220, 53, 69, 0.2); border: 1px solid #dc3545; color: #dc3545; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
<?php echo $error; ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div style="background: rgba(40, 167, 69, 0.2); border: 1px solid #28a745; color: #28a745; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
<?php echo $success; ?>
</div>
<?php endif; ?>
<form method="POST" action="register.php">
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Full Name *</label>
<input type="text" name="name" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Email Address *</label>
<input type="email" name="email" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Password *</label>
<input type="password" name="password" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Confirm Password *</label>
<input type="password" name="confirm_password" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<button type="submit" class="btn btn-primary w-100 mb-4">Register</button>
<p class="text-center" style="color: var(--text-muted);">
Already have an account? <a href="login.php" style="color: var(--accent-gold); text-decoration: none;">Login here</a>
</p>
</form>
</div>
</div>
</main>
<?php include 'includes/footer.php'; ?>