From 85893154df645a2ef26b191a42ad97b2494e563a Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 5 Oct 2025 15:36:57 +0000 Subject: [PATCH] 2 --- community.php | 50 ++++++++++++ create_post.php | 72 +++++++++++++++++ dashboard.php | 53 +++++++++++++ db/migrate.php | 32 ++++++++ db/migrations/001_create_users_table.sql | 9 +++ db/migrations/002_create_posts_table.sql | 9 +++ includes/footer.php | 17 ++++ includes/header.php | 46 +++++++++++ index.php | 58 +------------- login.php | 78 +++++++++++++++++++ logout.php | 6 ++ my_trips.php | 2 + plan_trip.php | 2 + profile.php | 2 + signup.php | 99 ++++++++++++++++++++++++ 15 files changed, 480 insertions(+), 55 deletions(-) create mode 100644 community.php create mode 100644 create_post.php create mode 100644 dashboard.php create mode 100644 db/migrate.php create mode 100644 db/migrations/001_create_users_table.sql create mode 100644 db/migrations/002_create_posts_table.sql create mode 100644 includes/footer.php create mode 100644 includes/header.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 my_trips.php create mode 100644 plan_trip.php create mode 100644 profile.php create mode 100644 signup.php diff --git a/community.php b/community.php new file mode 100644 index 0000000..a12f851 --- /dev/null +++ b/community.php @@ -0,0 +1,50 @@ +query("SELECT posts.*, users.username FROM posts JOIN users ON posts.user_id = users.id ORDER BY posts.created_at DESC"); + $posts = $stmt->fetchAll(); +} catch (PDOException $e) { + // Handle error + echo "
Error fetching posts: " . $e->getMessage() . "
"; +} +?> + +
+
+
+
+

Community Feed

+ + Create Post + +
+ + +
+
+

No posts yet. Be the first to share your story!

+ + Login to Post + +
+
+ + +
+
+

+

+

Posted by on

+
+
+ + +
+
+
+ + diff --git a/create_post.php b/create_post.php new file mode 100644 index 0000000..c86fade --- /dev/null +++ b/create_post.php @@ -0,0 +1,72 @@ +prepare("INSERT INTO posts (user_id, title, content) VALUES (?, ?, ?)"); + $stmt->execute([$_SESSION['user_id'], $title, $content]); + header("Location: community.php"); + exit; + } catch (PDOException $e) { + $errors[] = "Database error: " . $e->getMessage(); + } + } +} +?> + +
+
+
+
+
+

Create a New Post

+ + +
+ +

+ +
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ + diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..526e02c --- /dev/null +++ b/dashboard.php @@ -0,0 +1,53 @@ + + +
+
+ + +
+
+

Dashboard

+
+ + Page not found.
'; + } + ?> + +
+ + + \ No newline at end of file diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..db44933 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,32 @@ + PDO::ERRMODE_EXCEPTION, + ]); + + // Create the database if it doesn't exist + $pdo_server->exec('CREATE DATABASE IF NOT EXISTS `'.DB_NAME.'`'); + echo "Database `".DB_NAME."` created or already exists.\n"; + + // Now, connect to the specific database + $pdo_db = db(); + + // Run all migrations + $migration_files = glob(__DIR__ . '/migrations/*.sql'); + sort($migration_files); + + foreach ($migration_files as $file) { + $sql = file_get_contents($file); + $pdo_db->exec($sql); + echo "Executed migration: " . basename($file) . "\n"; + } + + echo "All migrations successful!\n"; + +} catch (PDOException $e) { + die("Migration failed: " . $e->getMessage() . "\n"); +} + diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..fc7b7c1 --- /dev/null +++ b/db/migrations/001_create_users_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS `users` ( + `id` INT NOT NULL AUTO_INCREMENT, + `username` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NOT NULL, + `password` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/db/migrations/002_create_posts_table.sql b/db/migrations/002_create_posts_table.sql new file mode 100644 index 0000000..362a4d9 --- /dev/null +++ b/db/migrations/002_create_posts_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS `posts` ( + `id` INT NOT NULL AUTO_INCREMENT, + `user_id` INT NOT NULL, + `title` VARCHAR(255) NOT NULL, + `content` TEXT NOT NULL, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..d41928c --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,17 @@ + + + + + + + diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..83a525e --- /dev/null +++ b/includes/header.php @@ -0,0 +1,46 @@ + + + + + + + TripEase + + + + + + + + + + + + + + + diff --git a/index.php b/index.php index 4ca078a..36fb2d1 100644 --- a/index.php +++ b/index.php @@ -51,45 +51,9 @@ if (file_exists($cache_file) && (time() - filemtime($cache_file)) < $cache_ttl) if ($image_data) { $destination_image = $image_data; } -?> - - - - - - TripEase - - - - - - - - - - - - - - +require_once __DIR__ . '/includes/header.php'; +?>
@@ -184,20 +148,4 @@ if ($image_data) { - -
-
-

© 2025 TripEase. All Rights Reserved.

-

Privacy Policy

-
- - - -
-
-
- - - - - + diff --git a/login.php b/login.php new file mode 100644 index 0000000..e1472ed --- /dev/null +++ b/login.php @@ -0,0 +1,78 @@ +Registration successful! Please log in.'; +} + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $email = trim($_POST['email']); + $password = $_POST['password']; + + if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) { + $errors[] = 'A valid 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['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + header("Location: dashboard.php"); + exit; + } else { + $errors[] = 'Invalid email or password'; + } + } catch (PDOException $e) { + $errors[] = "Database error: " . $e->getMessage(); + } + } +} +?> + +
+
+
+
+
+

Login

+ + +
+ +

+ +
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..91d13cc --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +My Trips +

Here you can see and manage your planned trips.

diff --git a/plan_trip.php b/plan_trip.php new file mode 100644 index 0000000..2b4c162 --- /dev/null +++ b/plan_trip.php @@ -0,0 +1,2 @@ +

Plan a New Trip

+

Use this form to plan a new trip.

diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..5c0313b --- /dev/null +++ b/profile.php @@ -0,0 +1,2 @@ +

My Profile

+

Here you can view and edit your profile information.

diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..f3d0227 --- /dev/null +++ b/signup.php @@ -0,0 +1,99 @@ +prepare("SELECT id FROM users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $errors[] = 'Email address is already registered.'; + } else { + // Hash password + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + + // Insert user into database + $stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)"); + $stmt->execute([$username, $email, $hashed_password]); + + // Redirect to login page + header("Location: login.php?registered=true"); + exit; + } + } catch (PDOException $e) { + $errors[] = "Database error: " . $e->getMessage(); + } + } +} +?> + +
+
+
+
+
+

Sign Up

+ + +
+ +

+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ +