This commit is contained in:
Flatlogic Bot 2025-10-09 14:48:50 +00:00
parent 4f8582c432
commit 952205e132
10 changed files with 451 additions and 26 deletions

View File

@ -1,14 +1,52 @@
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
// Initialize Bootstrap components const sosButton = document.getElementById('sosButton');
var toastEl = document.getElementById('sosToast'); const sosToastEl = document.getElementById('sosToast');
var toast = new bootstrap.Toast(toastEl); const sosToast = new bootstrap.Toast(sosToastEl);
const toastBody = sosToastEl.querySelector('.toast-body');
const toastHeader = sosToastEl.querySelector('.toast-header .me-auto');
// SOS Button functionality
var sosButton = document.getElementById('sosButton');
if (sosButton) { if (sosButton) {
sosButton.addEventListener('click', function () { sosButton.addEventListener('click', function () {
// Show the toast notification // Disable button to prevent multiple clicks
toast.show(); sosButton.disabled = true;
sosButton.querySelector('.sos-text').textContent = 'Sending...';
fetch('sos.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
toastHeader.classList.remove('text-danger');
toastHeader.classList.add('text-success');
toastHeader.innerHTML = '<i class="bi bi-check-circle-fill"></i> SOS Sent';
toastBody.textContent = data.message;
} else {
toastHeader.classList.remove('text-success');
toastHeader.classList.add('text-danger');
toastHeader.innerHTML = '<i class="bi bi-exclamation-triangle-fill"></i> Error';
toastBody.textContent = data.message;
}
sosToast.show();
})
.catch(error => {
toastHeader.classList.remove('text-success');
toastHeader.classList.add('text-danger');
toastHeader.innerHTML = '<i class="bi bi-exclamation-triangle-fill"></i> Network Error';
toastBody.textContent = 'Could not connect to the server. Please check your connection.';
sosToast.show();
console.error('SOS fetch error:', error);
})
.finally(() => {
// Re-enable the button after a delay
setTimeout(() => {
sosButton.disabled = false;
sosButton.querySelector('.sos-text').textContent = 'SOS';
}, 5000); // 5-second cooldown
});
}); });
} }
}); });

View File

@ -1,12 +1,41 @@
<?php <?php
require_once __DIR__ . '/config.php'; require_once __DIR__ . '/config.php';
echo "Starting migration process...\n";
try { try {
$pdo = db(); $pdo = db();
$sql = file_get_contents(__DIR__ . '/migrations/001_create_users_table.sql');
// 1. Create migrations table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS migrations (migration VARCHAR(255) PRIMARY KEY, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
// 2. Get all migrations that have been run
$ran_migrations_stmt = $pdo->query("SELECT migration FROM migrations");
$ran_migrations = $ran_migrations_stmt->fetchAll(PDO::FETCH_COLUMN);
// 3. Get all migration files
$migration_files = glob(__DIR__ . '/migrations/*.sql');
sort($migration_files);
$migrations_to_run = array_filter($migration_files, function($file) use ($ran_migrations) {
return !in_array(basename($file), $ran_migrations);
});
if (empty($migrations_to_run)) {
echo "No new migrations to run.\n";
} else {
foreach ($migrations_to_run as $file) {
echo "Running migration: " . basename($file) . "...\n";
$sql = file_get_contents($file);
$pdo->exec($sql); $pdo->exec($sql);
echo "Migration successful: users table created.\n";
// 4. Record the migration
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
$stmt->execute([basename($file)]);
echo "Migration successful: " . basename($file) . "\n";
}
}
} catch (PDOException $e) { } catch (PDOException $e) {
die("Migration failed: " . $e->getMessage() . "\n"); die("Migration failed: " . $e->getMessage() . "\n");
} }

View File

@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS trips (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT(11) UNSIGNED NOT NULL,
destination VARCHAR(255) NOT NULL,
trip_time DATETIME NOT NULL,
status VARCHAR(50) DEFAULT 'planned',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);

View File

@ -1,3 +1,4 @@
<?php session_start(); ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -18,7 +19,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS --> <!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css"> <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head> </head>
<body> <body>
@ -34,7 +35,13 @@
<li class="nav-item"><a class="nav-link" href="#features">Features</a></li> <li class="nav-item"><a class="nav-link" href="#features">Features</a></li>
<li class="nav-item"><a class="nav-link" href="#about">About</a></li> <li class="nav-item"><a class="nav-link" href="#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="#contact">Contact</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="my-trips.php">My Trips</a></li>
<li class="nav-item"><a class="btn btn-outline-primary ms-lg-3" 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="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li> <li class="nav-item"><a class="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li>
<?php endif; ?>
</ul> </ul>
</div> </div>
</div> </div>

103
login.php
View File

@ -1,3 +1,102 @@
<?php <?php
// Placeholder for login page session_start();
phpinfo(); require_once 'db/config.php';
// If user is already logged in, redirect to trip setup
if (isset($_SESSION['user_id'])) {
header("Location: trip-setup.php");
exit();
}
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = trim($_POST['email']);
$password = $_POST['password'];
if (empty($email) || empty($password)) {
$error_message = 'Please fill in all fields.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = 'Invalid email format.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email");
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password_hash'])) {
// Password is correct, start session
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['name'];
$_SESSION['user_email'] = $user['email'];
header("Location: trip-setup.php");
exit();
} else {
$error_message = 'Invalid email or password.';
}
} catch (PDOException $e) {
$error_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>Login - HerWay</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<header class="bg-light py-3">
<div class="container d-flex justify-content-between align-items-center">
<a href="index.php" class="h1 text-decoration-none" style="color: #E83E8C;">HerWay</a>
<nav>
<a href="login.php" class="btn btn-outline-primary me-2">Login</a>
<a href="register.php" class="btn btn-primary">Sign Up</a>
</nav>
</div>
</header>
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h2 class="card-title text-center mb-4">Login</h2>
<?php if (!empty($error_message)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></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>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
<div class="card-footer text-center">
<p class="mb-0">Don't have an account? <a href="register.php">Sign up here</a>.</p>
</div>
</div>
</div>
</div>
</main>
<footer class="bg-light text-center py-4 mt-5">
<p>&copy; <?php echo date("Y"); ?> HerWay. All rights reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

6
logout.php Normal file
View File

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

142
my-trips.php Normal file
View File

@ -0,0 +1,142 @@
<?php
session_start();
require_once 'db/config.php';
// Redirect to login if user is not authenticated
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
$trips = [];
$error_message = '';
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT destination, trip_time, status, created_at FROM trips WHERE user_id = :user_id ORDER BY trip_time DESC");
$stmt->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$stmt->execute();
$trips = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
$success_message = '';
if (isset($_GET['status']) && $_GET['status'] === 'success') {
$success_message = 'Your trip has been successfully saved!';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Trips - HerWay</title>
<meta name="description" content="View your planned trips on HerWay.">
<!-- Google Fonts: Poppins -->
<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=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<!-- Header -->
<header class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand fw-bold" href="index.php">HerWay</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="index.php#features">Features</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<?php if (isset($_SESSION['user_id'])): ?>
<li class="nav-item"><a class="nav-link" href="my-trips.php">My Trips</a></li>
<li class="nav-item"><a class="btn btn-outline-primary ms-lg-3" 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="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</header>
<main class="py-5">
<section id="my-trips" class="container">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">My Planned Trips</h1>
<a href="trip-setup.php" class="btn btn-primary">Plan a New Trip</a>
</div>
<?php if (!empty($success_message)): ?>
<div class="alert alert-success"><?php echo htmlspecialchars($success_message); ?></div>
<?php endif; ?>
<?php if (!empty($error_message)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<?php if (empty($trips)): ?>
<p class="text-center text-muted">You have no planned trips yet.</p>
<?php else: ?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="table-light">
<tr>
<th>Destination</th>
<th>Date & Time</th>
<th>Status</th>
<th>Booked On</th>
</tr>
</thead>
<tbody>
<?php foreach ($trips as $trip): ?>
<tr>
<td><?php echo htmlspecialchars($trip['destination']); ?></td>
<td><?php echo htmlspecialchars(date('D, M j, Y, g:i A', strtotime($trip['trip_time']))); ?></td>
<td><span class="badge bg-primary"><?php echo htmlspecialchars(ucfirst($trip['status'])); ?></span></td>
<td><?php echo htmlspecialchars(date('M j, Y', strtotime($trip['created_at']))); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="py-4 bg-dark text-white">
<div class="container text-center">
<p>&copy; <?php echo date("Y"); ?> HerWay. All Rights Reserved.</p>
<p>
<a href="#" class="text-white">Privacy Policy</a> |
<a href="#" class="text-white">Terms of Service</a>
</p>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js"></script>
</body>
</html>

View File

@ -87,7 +87,13 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
<li class="nav-item"><a class="nav-link" href="index.php#features">Features</a></li> <li class="nav-item"><a class="nav-link" href="index.php#features">Features</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li> <li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li> <li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<?php if (isset($_SESSION['user_id'])): ?>
<li class="nav-item"><a class="nav-link" href="my-trips.php">My Trips</a></li>
<li class="nav-item"><a class="btn btn-outline-primary ms-lg-3" 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="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li> <li class="nav-item"><a class="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li>
<?php endif; ?>
</ul> </ul>
</div> </div>
</div> </div>

40
sos.php Normal file
View File

@ -0,0 +1,40 @@
<?php
session_start();
require_once __DIR__ . '/mail/MailService.php';
header('Content-Type: application/json');
$response = ['success' => false, 'message' => 'An unexpected error occurred.'];
$userName = 'An anonymous user';
$userEmail = 'Not provided';
if (isset($_SESSION['user_id'])) {
$userName = $_SESSION['user_name'];
$userEmail = $_SESSION['user_email'];
}
$subject = 'SOS Alert Triggered by ' . $userName;
$htmlBody = "<p>An SOS alert was triggered by:</p>"
. "<ul>"
. "<li><strong>Name:</strong> " . htmlspecialchars($userName) . "</li>"
. "<li><strong>Email:</strong> " . htmlspecialchars($userEmail) . "</li>"
. "<li><strong>Time:</strong> " . date('Y-m-d H:i:s') . " UTC</li>"
. "</ul>"
. "<p>Please take appropriate action immediately.</p>";
$textBody = "SOS Alert from " . $userName . " (" . $userEmail . ") at " . date('Y-m-d H:i:s') . " UTC.";
// Send the email. If no recipient is set in .env, it will use the default.
$result = MailService::sendMail(null, $subject, $htmlBody, $textBody);
if (!empty($result['success'])) {
$response['success'] = true;
$response['message'] = 'SOS alert sent successfully. Help is on the way.';
} else {
// In a real app, you would log this error in more detail.
$response['message'] = 'Failed to send SOS alert. Please try again or contact support.';
// For debugging, you might want to include the error, but not in production.
// $response['error'] = $result['error'];
}
echo json_encode($response);

View File

@ -1,3 +1,42 @@
<?php
session_start();
require_once 'db/config.php';
// Redirect to login if user is not authenticated
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
$error_message = '';
$success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$destination = trim($_POST['destination']);
$trip_time = trim($_POST['trip_time']);
if (empty($destination) || empty($trip_time)) {
$error_message = 'Please fill in all fields.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO trips (user_id, destination, trip_time) VALUES (:user_id, :destination, :trip_time)");
$stmt->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$stmt->bindParam(':destination', $destination, PDO::PARAM_STR);
$stmt->bindParam(':trip_time', $trip_time, PDO::PARAM_STR);
if ($stmt->execute()) {
header('Location: my-trips.php?status=success');
exit();
} else {
$error_message = 'Failed to save the trip. Please try again.';
}
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -18,7 +57,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS --> <!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css"> <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head> </head>
<body> <body>
@ -34,7 +73,13 @@
<li class="nav-item"><a class="nav-link" href="index.php#features">Features</a></li> <li class="nav-item"><a class="nav-link" href="index.php#features">Features</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li> <li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li> <li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<li class="nav-item"><a class="btn btn-primary ms-lg-3" href="#">Sign Up</a></li> <?php if (isset($_SESSION['user_id'])): ?>
<li class="nav-item"><a class="nav-link" href="my-trips.php">My Trips</a></li>
<li class="nav-item"><a class="btn btn-outline-primary ms-lg-3" 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="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li>
<?php endif; ?>
</ul> </ul>
</div> </div>
</div> </div>
@ -48,19 +93,23 @@
<h1 class="text-center mb-4">Plan Your Trip</h1> <h1 class="text-center mb-4">Plan Your Trip</h1>
<p class="text-center text-muted mb-5">Enter your destination and travel time to find verified travel companions.</p> <p class="text-center text-muted mb-5">Enter your destination and travel time to find verified travel companions.</p>
<form> <?php if (!empty($error_message)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form action="trip-setup.php" method="post">
<div class="mb-4"> <div class="mb-4">
<label for="destination" class="form-label fs-5">Where are you going?</label> <label for="destination" class="form-label fs-5">Where are you going?</label>
<input type="text" class="form-control form-control-lg" id="destination" placeholder="e.g., 'Mumbai', 'Delhi Airport Terminal 3'"> <input type="text" class="form-control form-control-lg" id="destination" name="destination" placeholder="e.g., 'Mumbai', 'Delhi Airport Terminal 3'" required>
</div> </div>
<div class="mb-4"> <div class="mb-4">
<label for="travel-time" class="form-label fs-5">When are you traveling?</label> <label for="trip_time" class="form-label fs-5">When are you traveling?</label>
<input type="datetime-local" class="form-control form-control-lg" id="travel-time"> <input type="datetime-local" class="form-control form-control-lg" id="trip_time" name="trip_time" required>
</div> </div>
<div class="text-center mt-5"> <div class="text-center mt-5">
<button type="submit" class="btn btn-primary btn-lg px-5">Find Matches</button> <button type="submit" class="btn btn-primary btn-lg px-5">Save Trip</button>
</div> </div>
</form> </form>
</div> </div>