Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
@ -1,60 +0,0 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
|
||||
|
||||
body {
|
||||
font-family: 'Inter', sans-serif;
|
||||
background-color: #F8F9FA;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.task-card {
|
||||
border-radius: 0.5rem;
|
||||
border: 1px solid #e9ecef;
|
||||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
|
||||
transition: box-shadow 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.task-card:hover {
|
||||
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.task-card.completed {
|
||||
background-color: #f8f9fa;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.task-card.completed .card-title,
|
||||
.task-card.completed .card-text {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #4A90E2;
|
||||
border-color: #4A90E2;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #357ABD;
|
||||
border-color: #357ABD;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background-color: #50E3C2;
|
||||
border-color: #50E3C2;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
background-color: #38A89D;
|
||||
border-color: #38A89D;
|
||||
}
|
||||
|
||||
.form-control, .form-select {
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.toast-container {
|
||||
z-index: 1090;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Initialize toasts if they are present
|
||||
var toastElList = [].slice.call(document.querySelectorAll('.toast'));
|
||||
var toastList = toastElList.map(function (toastEl) {
|
||||
return new bootstrap.Toast(toastEl, { delay: 3000 });
|
||||
});
|
||||
toastList.forEach(toast => toast.show());
|
||||
|
||||
// Add confirmation to delete buttons
|
||||
const deleteForms = document.querySelectorAll('form.delete-task-form');
|
||||
deleteForms.forEach(form => {
|
||||
form.addEventListener('submit', function (event) {
|
||||
if (!confirm('Are you sure you want to delete this task?')) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,8 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(255) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `username` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,12 +0,0 @@
|
||||
</main>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="text-center text-muted py-4 mt-5 border-top">
|
||||
<p class="mb-0">© <?php echo date('Y'); ?> MyTaskManager. Built with <a href="https://flatlogic.com" target="_blank" class="text-decoration-none">Flatlogic</a>.</p>
|
||||
</footer>
|
||||
|
||||
<!-- Scripts -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,91 +0,0 @@
|
||||
<?php
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Check for session message for toast notifications
|
||||
$message = null;
|
||||
if (isset($_SESSION['message'])) {
|
||||
$message = $_SESSION['message'];
|
||||
$message_type = $_SESSION['message_type'] ?? 'success';
|
||||
unset($_SESSION['message']);
|
||||
unset($_SESSION['message_type']);
|
||||
}
|
||||
|
||||
$current_user = $_SESSION['user_id'] ?? null;
|
||||
$current_username = $_SESSION['username'] ?? null;
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<!-- SEO and Meta Tags -->
|
||||
<title>MyTaskManager</title>
|
||||
<meta name="description" content="A simple and beautiful task manager built with Flatlogic.">
|
||||
<meta name="keywords" content="task manager, to-do list, productivity, project management, simple tasks, online to-do, Flatlogic Generator, php task manager">
|
||||
<meta property="og:title" content="MyTaskManager">
|
||||
<meta property="og:description" content="A simple and beautiful task manager built with Flatlogic.">
|
||||
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Navbar -->
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">
|
||||
<i class="bi bi-check2-square text-primary"></i>
|
||||
MyTaskManager
|
||||
</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">
|
||||
<?php if ($current_user): ?>
|
||||
<li class="nav-item">
|
||||
<span class="navbar-text me-3">
|
||||
Welcome, <?php echo htmlspecialchars($current_username); ?>
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-danger" 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" href="register.php">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="container my-5">
|
||||
|
||||
<!-- Toast Notification -->
|
||||
<?php if ($message): ?>
|
||||
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
||||
<div class="toast align-items-center text-white bg-<?php echo $message_type; ?> border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<?php echo htmlspecialchars($message); ?>
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
316
index.php
316
index.php
@ -1,172 +1,150 @@
|
||||
<?php
|
||||
// This must be the very first line to ensure sessions work correctly.
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Check if the user is logged in. If not, redirect to the login page.
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- CONFIG AND DB SETUP ---
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
// The user ID is now securely retrieved from the session.
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Idempotent table alteration to add user_id
|
||||
// This is a one-time setup; it's safe to run multiple times due to 'ADD COLUMN IF NOT EXISTS' or similar logic in some DBs, or it will error harmlessly if the column exists.
|
||||
// For broader compatibility, we'll wrap it in a try-catch that specifically ignores 'Duplicate column name' errors.
|
||||
try {
|
||||
$pdo->exec("ALTER TABLE tasks ADD COLUMN user_id INT NULL;");
|
||||
} catch (PDOException $e) {
|
||||
// Ignore error if the column already exists
|
||||
if (strpos($e->getMessage(), 'Duplicate column name') === false) {
|
||||
throw $e; // Re-throw if it's a different error
|
||||
}
|
||||
}
|
||||
|
||||
// --- HANDLE POST REQUESTS ---
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$action = $_POST['action'] ?? '';
|
||||
|
||||
if ($action === 'add_task') {
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
|
||||
if (!empty($title)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO tasks (title, description, user_id) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$title, $description, $user_id]);
|
||||
$_SESSION['message'] = 'Task added successfully!';
|
||||
$_SESSION['message_type'] = 'success';
|
||||
} else {
|
||||
$_SESSION['message'] = 'Task title cannot be empty.';
|
||||
$_SESSION['message_type'] = 'danger';
|
||||
}
|
||||
} elseif ($action === 'update_status') {
|
||||
$task_id = filter_var($_POST['task_id'] ?? 0, FILTER_VALIDATE_INT);
|
||||
$status = $_POST['status'] ?? 'pending'; // Get current status to toggle
|
||||
if ($task_id) {
|
||||
// Correctly toggle between pending and completed
|
||||
$new_status = ($status === 'completed') ? 'pending' : 'completed';
|
||||
$stmt = $pdo->prepare("UPDATE tasks SET status = ? WHERE id = ? AND user_id = ?");
|
||||
$stmt->execute([$new_status, $task_id, $user_id]);
|
||||
$_SESSION['message'] = 'Task status updated!';
|
||||
$_SESSION['message_type'] = 'success';
|
||||
}
|
||||
} elseif ($action === 'delete_task') {
|
||||
$task_id = filter_var($_POST['task_id'] ?? 0, FILTER_VALIDATE_INT);
|
||||
if ($task_id) {
|
||||
$stmt = $pdo->prepare("DELETE FROM tasks WHERE id = ? AND user_id = ?");
|
||||
$stmt->execute([$task_id, $user_id]);
|
||||
$_SESSION['message'] = 'Task deleted successfully!';
|
||||
$_SESSION['message_type'] = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to self to prevent form resubmission
|
||||
header("Location: " . $_SERVER['PHP_SELF']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- FETCH TASKS FOR DISPLAY ---
|
||||
// Ensure the 'status' column exists before querying, or handle its absence gracefully.
|
||||
// For now, we assume it exists or the ALTER TABLE above would have created it.
|
||||
$stmt = $pdo->prepare("SELECT id, title, description, status, created_at FROM tasks WHERE user_id = ? ORDER BY status ASC, created_at DESC");
|
||||
$stmt->execute([$user_id]);
|
||||
$tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// Log the error for debugging purposes
|
||||
error_log("Database error: " . $e->getMessage());
|
||||
|
||||
// Provide a user-friendly error message
|
||||
$error_message = "A database error occurred. Please try again later.";
|
||||
$tasks = []; // Ensure tasks is empty on error
|
||||
$_SESSION['message'] = $error_message;
|
||||
$_SESSION['message_type'] = 'danger';
|
||||
|
||||
// If the error was specifically about a missing 'status' column, we might want to try fetching without it or prompt for migration.
|
||||
// For this iteration, we'll assume the ALTER TABLE above handles it or the user will address it.
|
||||
}
|
||||
|
||||
// The header is now included AFTER all the logic, ensuring it's only included if the script runs successfully.
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
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');
|
||||
?>
|
||||
|
||||
<!-- Add Task Form -->
|
||||
<section id="add-task" class="mb-5">
|
||||
<div class="card task-card">
|
||||
<div class="card-body p-4">
|
||||
<h2 class="card-title h4 mb-3">Add a New Task</h2>
|
||||
<form action="index.php" method="POST">
|
||||
<input type="hidden" name="action" value="add_task">
|
||||
<div class="mb-3">
|
||||
<label for="title" class="form-label">Task Title</label>
|
||||
<input type="text" class="form-control" id="title" name="title" placeholder="e.g., Finish project report" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description (Optional)</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3" placeholder="Add more details about the task..."></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100 py-2">
|
||||
<i class="bi bi-plus-lg"></i> Add Task
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Task List -->
|
||||
<section id="task-list">
|
||||
<h2 class="h4 mb-4">Your Tasks</h2>
|
||||
<?php if (empty($tasks)): ?>
|
||||
<div class="text-center text-muted p-5 bg-light rounded-3">
|
||||
<i class="bi bi-clipboard-check" style="font-size: 3rem;"></i>
|
||||
<p class="mt-3 mb-0">You have no tasks yet. Add one above to get started!</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="list-group">
|
||||
<?php foreach ($tasks as $task):
|
||||
// Determine button class and icon based on task status
|
||||
$button_class = ($task['status'] === 'completed') ? 'btn-warning' : 'btn-success';
|
||||
$button_icon = ($task['status'] === 'completed') ? 'bi-arrow-counterclockwise' : 'bi-check-lg';
|
||||
$button_title = ($task['status'] === 'completed') ? 'Mark as pending' : 'Mark as completed';
|
||||
?>
|
||||
<div class="list-group-item list-group-item-action task-card <?php echo $task['status'] === 'completed' ? 'completed' : ''; ?>">
|
||||
<div class="d-flex w-100 justify-content-between">
|
||||
<div>
|
||||
<h5 class="mb-1"><?php echo htmlspecialchars($task['title']); ?></h5>
|
||||
<p class="mb-1 small text-muted"><?php echo htmlspecialchars($task['description']); ?></p>
|
||||
</div>
|
||||
<div class="d-flex gap-2 align-items-center">
|
||||
<form action="index.php" method="POST" class="d-inline">
|
||||
<input type="hidden" name="action" value="update_status">
|
||||
<input type="hidden" name="task_id" value="<?php echo $task['id']; ?>">
|
||||
<input type="hidden" name="status" value="<?php echo $task['status']; ?>">
|
||||
<button type="submit" class="btn btn-sm <?php echo $button_class; ?>" title="<?php echo $button_title; ?>">
|
||||
<i class="bi <?php echo $button_icon; ?>"></i>
|
||||
</button>
|
||||
</form>
|
||||
<form action="index.php" method="POST" class="d-inline delete-task-form">
|
||||
<input type="hidden" name="action" value="delete_task">
|
||||
<input type="hidden" name="task_id" value="<?php echo $task['id']; ?>">
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger" title="Delete task">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<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>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
87
login.php
87
login.php
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$errors = [];
|
||||
$username = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$username = trim($_POST['username'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
// Validation
|
||||
if (empty($username)) {
|
||||
$errors[] = 'Username is required.';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required.';
|
||||
}
|
||||
|
||||
// If no validation errors, check credentials
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT id, username, password FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
// Regenerate session ID to prevent session fixation
|
||||
session_regenerate_id(true);
|
||||
|
||||
// Store user info in session
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
|
||||
// Redirect to the main page
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
} else {
|
||||
$errors[] = 'Invalid username or password.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="card task-card">
|
||||
<div class="card-body p-4">
|
||||
<h1 class="card-title h3 mb-4 text-center">Login to Your Account</h1>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="login.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars($username); ?>" 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 w-100 py-2">Login</button>
|
||||
</form>
|
||||
<div class="text-center mt-4">
|
||||
<p class="mb-0">Don't have an account? <a href="register.php">Register here</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
28
logout.php
28
logout.php
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Unset all of the session variables
|
||||
$_SESSION = [];
|
||||
|
||||
// Destroy the session
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
session_destroy();
|
||||
|
||||
// Start a new session to pass a logout message
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
$_SESSION['message'] = 'You have been logged out successfully.';
|
||||
$_SESSION['message_type'] = 'success';
|
||||
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
93
register.php
93
register.php
@ -1,93 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$errors = [];
|
||||
$username = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$username = trim($_POST['username'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
// Validation
|
||||
if (empty($username)) {
|
||||
$errors[] = 'Username is required.';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required.';
|
||||
} elseif (strlen($password) < 6) {
|
||||
$errors[] = 'Password must be at least 6 characters long.';
|
||||
}
|
||||
|
||||
// Check if username already exists
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
if ($stmt->fetch()) {
|
||||
$errors[] = 'Username already taken. Please choose another one.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// If no errors, create user
|
||||
if (empty($errors)) {
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)");
|
||||
$stmt->execute([$username, $hashed_password]);
|
||||
|
||||
$_SESSION['message'] = 'Registration successful! You can now log in.';
|
||||
$_SESSION['message_type'] = 'success';
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error on user creation: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="card task-card">
|
||||
<div class="card-body p-4">
|
||||
<h1 class="card-title h3 mb-4 text-center">Create Your Account</h1>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="register.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars($username); ?>" 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 class="form-text">Password must be at least 6 characters long.</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100 py-2">Register</button>
|
||||
</form>
|
||||
<div class="text-center mt-4">
|
||||
<p class="mb-0">Already have an account? <a href="login.php">Log in here</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user