Auto commit: 2025-10-07T19:47:56.054Z

This commit is contained in:
Flatlogic Bot 2025-10-07 19:47:56 +00:00
parent 19713d7205
commit 363f73447c
9 changed files with 281 additions and 58 deletions

21
dashboard.php Normal file
View File

@ -0,0 +1,21 @@
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
?>
<?php include 'partials/header.php'; ?>
<div class="container py-5">
<div class="row">
<div class="col-md-12">
<h2 class="text-center mb-4">Dashboard</h2>
<p class="text-center">Welcome, <?php echo htmlspecialchars($_SESSION['user_email']); ?>!</p>
<p class="text-center">This is your dashboard. More features will be added soon.</p>
</div>
</div>
</div>
<?php include 'partials/footer.php'; ?>

18
db/migrate.php Normal file
View File

@ -0,0 +1,18 @@
<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
$migrationsDir = __DIR__ . '/migrations';
$files = glob($migrationsDir . '/*.sql');
foreach ($files as $file) {
$sql = file_get_contents($file);
$pdo->exec($sql);
echo "Migration from $file executed successfully.\n";
}
} catch (PDOException $e) {
die("Database migration failed: " . $e->getMessage());
}

View File

@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`email` VARCHAR(255) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

View File

@ -1,46 +1,4 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FoodBridge - Connecting NGOs and Restaurants</title>
<meta name="description" content="FoodBridge is a platform dedicated to connecting NGOs with restaurants to redistribute surplus food and fight hunger.">
<meta name="keywords" content="food donation, surplus food, NGO, restaurant, community support, food waste reduction, hunger relief, non-profit, food security, social impact, Built with Flatlogic Generator">
<meta property="og:title" content="FoodBridge - Connecting NGOs and Restaurants">
<meta property="og:description" content="Join FoodBridge to connect with local partners, reduce food waste, and support your community.">
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? 'https://picsum.photos/seed/social/1200/630'); ?>">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? 'https://picsum.photos/seed/social/1200/630'); ?>">
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- Google Fonts -->
<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=Lato:wght@400;700&family=Merriweather:wght@700&display=swap" rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand" href="#">FoodBridge</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="#ngos">For NGOs</a></li>
<li class="nav-item"><a class="nav-link" href="#restaurants">For Restaurants</a></li>
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
<?php include 'partials/header.php'; ?>
<header id="hero" class="hero-section">
<div class="container text-center">
@ -85,7 +43,7 @@
<div class="col-md-6">
<h2 class="section-title mb-4">For NGOs</h2>
<p>Access a steady stream of quality food donations from local restaurants. Reduce your operational costs, expand your reach, and focus on what you do best: serving the community.</p>
<a href="#" class="btn btn-primary">Register your NGO</a>
<a href="/signup.php" class="btn btn-primary">Register your NGO</a>
</div>
<div class="col-md-6">
<img src="https://picsum.photos/seed/ngo/800/600" class="img-fluid rounded shadow" alt="A smiling volunteer from an NGO receiving a food donation.">
@ -100,7 +58,7 @@
<div class="col-md-6">
<h2 class="section-title mb-4">For Restaurants</h2>
<p>Reduce food waste, gain tax benefits, and build a positive brand image. Donating your surplus food is simple, efficient, and makes a tangible impact in your local community.</p>
<a href="#" class="btn btn-secondary">Register your Restaurant</a>
<a href="/signup.php" class="btn btn-secondary">Register your Restaurant</a>
</div>
<div class="col-md-6">
<img src="https://picsum.photos/seed/restaurant/800/600" class="img-fluid rounded shadow" alt="A chef plating food in a restaurant kitchen, representing food donation.">
@ -135,16 +93,4 @@
</section>
</main>
<footer class="py-4 text-center">
<div class="container">
<p>&copy; <?php echo date("Y"); ?> FoodBridge. All Rights Reserved.</p>
<p><a href="/privacy.php">Privacy Policy</a></p>
</div>
</footer>
<!-- Bootstrap 5 JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<!-- Custom JS -->
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>
<?php include 'partials/footer.php'; ?>

71
login.php Normal file
View File

@ -0,0 +1,71 @@
<?php
require_once 'db/config.php';
$errors = [];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email)) {
$errors[] = 'Email is required';
}
if (empty($password)) {
$errors[] = 'Password is required';
}
if (empty($errors)) {
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_start();
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_email'] = $user['email'];
header("Location: dashboard.php");
exit;
} else {
$errors[] = 'Invalid email or password';
}
} catch (PDOException $e) {
$errors[] = "Database error: " . $e->getMessage();
}
}
}
?>
<?php include 'partials/header.php'; ?>
<div class="container py-5">
<div class="row">
<div class="col-md-6 mx-auto">
<h2 class="text-center mb-4">Login</h2>
<?php if (!empty($errors)):
?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p><?php echo $error; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form action="login.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>
<?php include 'partials/footer.php'; ?>

7
logout.php Normal file
View File

@ -0,0 +1,7 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: /");
exit;
?>

13
partials/footer.php Normal file
View File

@ -0,0 +1,13 @@
<footer class="py-4 text-center">
<div class="container">
<p>&copy; <?php echo date("Y"); ?> FoodBridge. All Rights Reserved.</p>
<p><a href="/privacy.php">Privacy Policy</a></p>
</div>
</footer>
<!-- Bootstrap 5 JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<!-- Custom JS -->
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>

52
partials/header.php Normal file
View File

@ -0,0 +1,52 @@
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FoodBridge - Connecting NGOs and Restaurants</title>
<meta name="description" content="FoodBridge is a platform dedicated to connecting NGOs with restaurants to redistribute surplus food and fight hunger.">
<meta name="keywords" content="food donation, surplus food, NGO, restaurant, community support, food waste reduction, hunger relief, non-profit, food security, social impact, Built with Flatlogic Generator">
<meta property="og:title" content="FoodBridge - Connecting NGOs and Restaurants">
<meta property="og:description" content="Join FoodBridge to connect with local partners, reduce food waste, and support your community.">
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? 'https://picsum.photos/seed/social/1200/630'); ?>">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? 'https://picsum.photos/seed/social/1200/630'); ?>">
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- Google Fonts -->
<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=Lato:wght@400;700&family=Merriweather:wght@700&display=swap" rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand" href="/">FoodBridge</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="/#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="/#ngos">For NGOs</a></li>
<li class="nav-item"><a class="nav-link" href="/#restaurants">For Restaurants</a></li>
<li class="nav-item"><a class="nav-link" href="/#contact">Contact</a></li>
<?php if (isset($_SESSION['user_id'])):
?>
<li class="nav-item"><a class="nav-link" href="/dashboard.php">Dashboard</a></li>
<li class="nav-item"><a class="nav-link" href="/logout.php">Logout</a></li>
<?php else: ?>
<li class="nav-item"><a class="nav-link" href="/login.php">Login</a></li>
<li class="nav-item"><a class="nav-link" href="/signup.php">Sign Up</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>

89
signup.php Normal file
View File

@ -0,0 +1,89 @@
<?php
require_once 'db/config.php';
$errors = [];
$success = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$password_confirm = $_POST['password_confirm'] ?? '';
if (empty($email)) {
$errors[] = 'Email is required';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Invalid email format';
}
if (empty($password)) {
$errors[] = 'Password is required';
}
if ($password !== $password_confirm) {
$errors[] = 'Passwords do not match';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$errors[] = 'Email already exists';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (email, password) VALUES (?, ?)");
$stmt->execute([$email, $hashed_password]);
$success = 'Registration successful! You can now <a href="login.php">login</a>.';
}
} catch (PDOException $e) {
$errors[] = "Database error: " . $e->getMessage();
}
}
}
?>
<?php include 'partials/header.php'; ?>
<div class="container py-5">
<div class="row">
<div class="col-md-6 mx-auto">
<h2 class="text-center mb-4">Sign Up</h2>
<?php if (!empty($errors)):
?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p><?php echo $error; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success">
<p><?php echo $success; ?></p>
</div>
<?php else: ?>
<form action="signup.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>
<div class="mb-3">
<label for="password_confirm" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
</div>
<button type="submit" class="btn btn-primary">Sign Up</button>
</form>
<?php endif; ?>
</div>
</div>
</div>
<?php include 'partials/footer.php'; ?>