Compare commits

..

2 Commits

Author SHA1 Message Date
Flatlogic Bot
d0561ab2af 1.2 2025-11-07 05:45:29 +00:00
Flatlogic Bot
01b406af83 1.1 2025-11-07 05:44:17 +00:00
15 changed files with 703 additions and 143 deletions

6
assets/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

52
assets/css/custom.css Normal file
View File

@ -0,0 +1,52 @@
:root {
--primary-color: #2C5A3D;
--secondary-color: #F4EAD5;
--background-color: #F8F9FA;
--surface-color: #FFFFFF;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: var(--background-color);
}
.navbar-brand {
color: var(--primary-color) !important;
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-primary:hover {
background-color: #21422c;
border-color: #21422c;
}
.btn-secondary {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
color: #333;
}
.text-primary {
color: var(--primary-color) !important;
}
.hero-section {
background-image: linear-gradient(rgba(44, 90, 61, 0.8), rgba(44, 90, 61, 0.6)), url('https://images.pexels.com/photos/221540/pexels-photo-221540.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1');
background-size: cover;
background-position: center;
padding: 10rem 0;
}
.card {
border: none;
border-radius: 0.5rem;
transition: transform 0.2s;
}
.card:hover {
transform: translateY(-5px);
}

7
assets/js/bootstrap.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

39
assets/js/main.js Normal file
View File

@ -0,0 +1,39 @@
document.addEventListener('DOMContentLoaded', function () {
const contactForm = document.getElementById('contact-form');
const contactToast = new bootstrap.Toast(document.getElementById('contact-toast'));
if (contactForm) {
contactForm.addEventListener('submit', function (e) {
e.preventDefault();
const formData = new FormData(contactForm);
fetch('contact_handler.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
const toastBody = document.querySelector('#contact-toast .toast-body');
if (data.success) {
toastBody.textContent = 'Thank you for your message! We will get back to you shortly.';
contactForm.reset();
} else {
toastBody.textContent = data.error || 'An error occurred. Please try again.';
}
contactToast.show();
})
.catch(error => {
const toastBody = document.querySelector('#contact-toast .toast-body');
toastBody.textContent = 'A network error occurred. Please try again.';
contactToast.show();
});
});
}
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('error')) {
const loginModal = new bootstrap.Modal(document.getElementById('loginModal'));
loginModal.show();
}
});

18
auth.php Normal file
View File

@ -0,0 +1,18 @@
<?php
session_start();
function require_login($role = null) {
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
if ($role && $_SESSION['user_role'] !== $role) {
// Redirect to their own dashboard if they try to access a page for another role
if ($_SESSION['user_role'] === 'owner') {
header('Location: dashboard_owner.php');
} else {
header('Location: dashboard_client.php');
}
exit();
}
}

35
contact_handler.php Normal file
View File

@ -0,0 +1,35 @@
<?php
require_once __DIR__ . '/mail/MailService.php';
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'error' => 'Invalid request method.']);
exit;
}
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$message = isset($_POST['message']) ? trim($_POST['message']) : '';
if (empty($name) || empty($email) || empty($message)) {
echo json_encode(['success' => false, 'error' => 'Please fill out all fields.']);
exit;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo json_encode(['success' => false, 'error' => 'Invalid email format.']);
exit;
}
$to = getenv('MAIL_TO') ?: null; // Use environment variable or default in MailService
$subject = 'New Contact Form Submission from ' . $name;
$res = MailService::sendContactMessage($name, $email, $message, $to, $subject);
if (!empty($res['success'])) {
echo json_encode(['success' => true]);
} else {
error_log('MailService Error: ' . ($res['error'] ?? 'Unknown error'));
echo json_encode(['success' => false, 'error' => 'Sorry, there was an issue sending your message. Please try again later.']);
}

34
dashboard_client.php Normal file
View File

@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/auth.php';
require_login('client');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Client Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Client Portal</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<h1>Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h1>
<p>This is your client portal. Here you can view your project information.</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

43
dashboard_owner.php Normal file
View File

@ -0,0 +1,43 @@
<?php
require_once __DIR__ . '/auth.php';
require_login('owner');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Owner Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Owner Dashboard</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="register.php">Create User</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<h1>Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h1>
<p>This is your dashboard. From here you can manage your business.</p>
<div class="mt-5">
<h2>Quick Actions</h2>
<a href="register.php" class="btn btn-primary">Create a New User</a>
<!-- More actions will be added here -->
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

8
db/schema.sql Normal file
View File

@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`role` ENUM('owner', 'client') NOT NULL DEFAULT 'client',
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

342
index.php
View File

@ -1,150 +1,206 @@
<?php <!DOCTYPE html>
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Style</title> <title>landscaping app</title>
<?php <meta name="description" content="Built with Flatlogic Generator">
// Read project preview data from environment <meta name="keywords" content="landscaping management, client portal, job scheduling, landscaping bids, lawn care app, garden maintenance, Built with Flatlogic Generator">
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? ''; <meta property="og:title" content="landscaping app">
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; <meta property="og:description" content="Built with Flatlogic Generator">
?> <meta property="og:image" content="">
<?php if ($projectDescription): ?> <meta name="twitter:card" content="summary_large_image">
<!-- Meta description --> <meta name="twitter:image" content="">
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags --> <!-- Bootstrap CSS -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" /> <link href="assets/css/bootstrap.min.css?v=<?php echo time(); ?>" rel="stylesheet">
<!-- Twitter meta tags --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?> <!-- Google Fonts (Inter) -->
<?php if ($projectImageUrl): ?> <link rel="preconnect" href="https://fonts.googleapis.com">
<!-- Open Graph image --> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" /> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" /> <!-- Custom CSS -->
<?php endif; ?> <link rel="stylesheet" href="assets/css/custom.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head> </head>
<body> <body>
<main>
<div class="card"> <!-- Header -->
<h1>Analyzing your requirements and generating your website…</h1> <nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes"> <div class="container">
<span class="sr-only">Loading…</span> <a class="navbar-brand fw-bold" href="#">Greenscape Portal</a>
</div> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p> <span class="navbar-toggler-icon"></span>
<p class="hint">This page will update automatically as the plan is implemented.</p> </button>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="#services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
<li class="nav-item ms-lg-3">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#loginModal">
Client Login
</button>
</li>
</ul>
</div>
</div>
</nav>
<!-- Hero Section -->
<header class="hero-section text-white text-center">
<div class="container">
<h1 class="display-4 fw-bold">Professional Landscaping, Seamlessly Managed</h1>
<p class="lead my-4">Your client portal for easy job tracking, billing, and communication.</p>
<a href="#contact" class="btn btn-lg btn-secondary">Get a Free Estimate</a>
</div>
</header>
<!-- Services Section -->
<section id="services" class="py-5">
<div class="container">
<h2 class="text-center mb-5">Our Services</h2>
<div class="row text-center">
<div class="col-md-4 mb-4">
<div class="card h-100 shadow-sm">
<div class="card-body">
<i class="bi bi-tree-fill fs-1 text-primary"></i>
<h5 class="card-title mt-3">Garden Design</h5>
<p class="card-text">Beautiful, sustainable garden designs tailored to your space and vision.</p>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card h-100 shadow-sm">
<div class="card-body">
<i class="bi bi-scissors fs-1 text-primary"></i>
<h5 class="card-title mt-3">Lawn Maintenance</h5>
<p class="card-text">Reliable mowing, trimming, and fertilization to keep your lawn pristine.</p>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card h-100 shadow-sm">
<div class="card-body">
<i class="bi bi-bricks fs-1 text-primary"></i>
<h5 class="card-title mt-3">Hardscaping</h5>
<p class="card-text">Patios, walkways, and retaining walls that enhance your outdoor living area.</p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Portfolio Section -->
<section id="portfolio" class="py-5 bg-light">
<div class="container">
<h2 class="text-center mb-5">Before & After</h2>
<div class="row g-4">
<div class="col-md-6">
<div class="card shadow-sm">
<img src="https://images.pexels.com/photos/3049121/pexels-photo-3049121.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" class="card-img-top" alt="Before landscaping">
<div class="card-body">
<h5 class="card-title">Suburban Revival: Before</h5>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card shadow-sm">
<img src="https://images.pexels.com/photos/2980955/pexels-photo-2980955.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" class="card-img-top" alt="After landscaping">
<div class="card-body">
<h5 class="card-title">Suburban Revival: After</h5>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Contact Section -->
<section id="contact" class="py-5">
<div class="container">
<h2 class="text-center mb-5">Contact Us</h2>
<div class="row">
<div class="col-md-8 mx-auto">
<form id="contact-form" action="contact_handler.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">Send Message</button>
</form>
</div>
</div>
</div>
</section>
<!-- Login Modal -->
<div class="modal fade" id="loginModal" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="loginModalLabel">Client Login</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<?php if(isset($_GET['error'])): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($_GET['error']); ?></div>
<?php endif; ?>
<form action="login_handler.php" method="POST">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
</div>
</div>
</div> </div>
</main>
<footer> <!-- Footer -->
Page updated: <?= htmlspecialchars($now) ?> (UTC) <footer class="py-4 bg-dark text-white text-center">
</footer> <div class="container">
<p class="mb-0">&copy; 2025 Greenscape Portal. All Rights Reserved.</p>
</div>
</footer>
<!-- Toast Notification -->
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
<div id="contact-toast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto">Greenscape Portal</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
<!-- Message will be inserted here -->
</div>
</div>
</div>
<!-- Bootstrap JS -->
<script src="assets/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body> </body>
</html> </html>

43
login_handler.php Normal file
View File

@ -0,0 +1,43 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email) || empty($password)) {
header('Location: index.php?error=Email and password are required.');
exit();
}
try {
$pdo = db();
$stmt = $pdo->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'];
if ($user['role'] === 'owner') {
header('Location: dashboard_owner.php');
} else {
header('Location: dashboard_client.php');
}
exit();
} else {
header('Location: index.php?error=Invalid email or password.');
exit();
}
} catch (PDOException $e) {
// In a real app, you would log this error.
header('Location: index.php?error=An internal error occurred.');
exit();
}
} else {
header('Location: login.php');
exit();
}

6
logout.php Normal file
View File

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header('Location: login.php');
exit();

60
register.php Normal file
View File

@ -0,0 +1,60 @@
<?php
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create New User</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="dashboard_owner.php">Owner Dashboard</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<h2>Create a New User</h2>
<?php if(isset($_GET['error'])): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($_GET['error']); ?></div>
<?php endif; ?>
<?php if(isset($_GET['success'])): ?>
<div class="alert alert-success"><?php echo htmlspecialchars($_GET['success']); ?></div>
<?php endif; ?>
<form action="register_handler.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Full Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role">
<option value="client">Client</option>
<option value="owner">Owner</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Create User</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

51
register_handler.php Normal file
View File

@ -0,0 +1,51 @@
<?php
require_once __DIR__ . '/db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$role = $_POST['role'] ?? 'client';
if (empty($name) || empty($email) || empty($password)) {
header('Location: register.php?error=All fields are required.');
exit();
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header('Location: register.php?error=Invalid email format.');
exit();
}
if ($role !== 'owner' && $role !== 'client') {
header('Location: register.php?error=Invalid role specified.');
exit();
}
try {
$pdo = db();
// Check if email already exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
header('Location: register.php?error=Email already in use.');
exit();
}
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $email, $hashed_password, $role]);
header('Location: register.php?success=User created successfully.');
exit();
} catch (PDOException $e) {
header('Location: register.php?error=A database error occurred.');
exit();
}
} else {
header('Location: register.php');
exit();
}

102
signup.php Normal file
View File

@ -0,0 +1,102 @@
<?php
// Simple, standalone registration page
// No authentication required
require_once 'db/config.php';
$message = '';
// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$role = $_POST['role'] ?? 'client'; // Default to 'client'
if (empty($name) || empty($email) || empty($password)) {
$message = "Please fill in all fields.";
} else {
// Hash the password for security
$password_hash = password_hash($password, PASSWORD_DEFAULT);
try {
$pdoconn = db();
// Prepare SQL statement to prevent SQL injection
$sql = "INSERT INTO users (name, email, password, role) VALUES (:name, :email, :password, :role)";
$stmt = $pdoconn->prepare($sql);
// Bind parameters
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':password', $password_hash);
$stmt->bindParam(':role', $role);
// Execute the statement
if ($stmt->execute()) {
$message = "Registration successful! You can now log in.";
} else {
$message = "Error: Could not execute the query.";
}
} catch (PDOException $e) {
// Check for duplicate entry
if ($e->errorInfo[1] == 1062) {
$message = "This email address is already registered.";
} else {
$message = "Database error: " . $e->getMessage();
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up</title>
<link href="assets/css/bootstrap.min.css?v=<?php echo time(); ?>" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3>Create an Account</h3>
</div>
<div class="card-body">
<?php if (!empty($message)): ?>
<div class="alert alert-info"><?php echo htmlspecialchars($message); ?></div>
<?php endif; ?>
<form action="signup.php" method="post">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role">
<option value="owner">Owner</option>
<option value="client">Client</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Sign Up</button>
</form>
</div>
<div class="card-footer">
<a href="index.php">Back to Home</a>
</div>
</div>
</div>
</div>
</div>
<script src="assets/js/bootstrap.bundle.min.js?v=<?php echo time(); ?>"></script>
</body>
</html>