Deploy from Lumerel
This commit is contained in:
54
.docker/99-migrate.sh
Normal file
54
.docker/99-migrate.sh
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# IMPORTANT: This script is sourced (not executed) by the webdevops entrypoint.
|
||||
# Never use "exit" — it would kill the parent entrypoint and prevent supervisord from starting.
|
||||
# Use "return" instead to leave this script without affecting the parent.
|
||||
|
||||
echo ">>> Waiting for database connection..."
|
||||
echo ">>> DB_HOST=${DB_HOST:-NOT SET}"
|
||||
echo ">>> DB_PORT=${DB_PORT:-NOT SET}"
|
||||
echo ">>> DB_DATABASE=${DB_DATABASE:-NOT SET}"
|
||||
echo ">>> DB_USERNAME=${DB_USERNAME:-NOT SET}"
|
||||
echo ">>> DB_PASSWORD is $([ -n "$DB_PASSWORD" ] && echo 'set' || echo 'NOT SET')"
|
||||
|
||||
if [ -z "$DB_HOST" ] || [ -z "$DB_USERNAME" ]; then
|
||||
echo ">>> ERROR: DB_HOST or DB_USERNAME not set. Skipping migrations."
|
||||
return 0 2>/dev/null || true
|
||||
fi
|
||||
|
||||
_migrate_max_retries=30
|
||||
_migrate_count=0
|
||||
_migrate_done=false
|
||||
|
||||
while [ $_migrate_count -lt $_migrate_max_retries ]; do
|
||||
if php -r '
|
||||
try {
|
||||
$host = getenv("DB_HOST");
|
||||
$port = getenv("DB_PORT") ?: "3306";
|
||||
$user = getenv("DB_USERNAME");
|
||||
$pass = getenv("DB_PASSWORD");
|
||||
new PDO("mysql:host=$host;port=$port", $user, $pass, [PDO::ATTR_TIMEOUT => 3]);
|
||||
exit(0);
|
||||
} catch (Throwable $e) {
|
||||
fwrite(STDERR, "PDO error: " . $e->getMessage() . "\n");
|
||||
exit(1);
|
||||
}
|
||||
' 2>&1; then
|
||||
echo ">>> Database is reachable. Running migrations..."
|
||||
if php /app/migrate.php; then
|
||||
echo ">>> Migrations completed successfully."
|
||||
else
|
||||
echo ">>> WARNING: migrate.php exited with code $?"
|
||||
fi
|
||||
_migrate_done=true
|
||||
break
|
||||
fi
|
||||
|
||||
_migrate_count=$((_migrate_count + 1))
|
||||
echo ">>> Waiting for database... attempt $_migrate_count/$_migrate_max_retries"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
if [ "$_migrate_done" = false ]; then
|
||||
echo ">>> WARNING: Could not connect to database after $_migrate_max_retries attempts. Skipping migrations."
|
||||
fi
|
||||
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
.git
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM webdevops/php-nginx:8.3-alpine
|
||||
ENV WEB_DOCUMENT_ROOT=/app/public
|
||||
ARG CACHE_BUST=1771284989
|
||||
COPY . /app
|
||||
RUN echo "index index.php index.html index.htm;" > /opt/docker/etc/nginx/vhost.common.d/01-index.conf \
|
||||
&& echo "add_header Cache-Control 'no-cache, no-store, must-revalidate';" > /opt/docker/etc/nginx/vhost.common.d/02-no-cache.conf
|
||||
RUN set -e; if [ -f /app/composer.json ]; then \
|
||||
echo ">>> composer.json found, installing dependencies..."; \
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer; \
|
||||
cd /app && composer install --no-dev --no-interaction --optimize-autoloader; \
|
||||
ls -la /app/vendor/autoload.php; \
|
||||
else \
|
||||
echo ">>> No composer.json found, skipping composer install"; \
|
||||
fi
|
||||
RUN set -e; if [ -f /app/package.json ]; then \
|
||||
echo ">>> package.json found, installing node dependencies..."; \
|
||||
apk add --no-cache nodejs npm; \
|
||||
cd /app && npm install --production; \
|
||||
else \
|
||||
echo ">>> No package.json found, skipping npm install"; \
|
||||
fi
|
||||
COPY --chmod=755 .docker/99-migrate.sh /opt/docker/provision/entrypoint.d/99-migrate.sh
|
||||
RUN chown -R application:application /app
|
||||
15
composer.json
Normal file
15
composer.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "taskit/project-management",
|
||||
"description": "Modern Project Management System",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"ext-pdo": "*",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
15
db.php
Normal file
15
db.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
'mysql:host=' . getenv('DB_HOST') . ';port=' . getenv('DB_PORT') . ';dbname=' . getenv('DB_DATABASE'),
|
||||
getenv('DB_USERNAME'),
|
||||
getenv('DB_PASSWORD'),
|
||||
[
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'
|
||||
]
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
die("Database connection failed: " . $e->getMessage());
|
||||
}
|
||||
33
migrate.php
Normal file
33
migrate.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
require_once 'db.php';
|
||||
|
||||
// Ensure migrations table exists
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS migrations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
migration VARCHAR(255) NOT NULL UNIQUE,
|
||||
ran_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)");
|
||||
|
||||
// Get already run migrations
|
||||
$stmt = $pdo->query("SELECT migration FROM migrations");
|
||||
$ranMigrations = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Scan migrations directory
|
||||
$migrationFiles = glob('migrations/*.php');
|
||||
sort($migrationFiles);
|
||||
|
||||
foreach ($migrationFiles as $migrationFile) {
|
||||
$migrationName = basename($migrationFile);
|
||||
|
||||
if (!in_array($migrationName, $ranMigrations)) {
|
||||
require_once $migrationFile;
|
||||
|
||||
// Record migration as run
|
||||
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||
$stmt->execute([$migrationName]);
|
||||
|
||||
echo "Ran migration: $migrationName\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "Migrations complete.";
|
||||
9
migrations/001_create_users_table.php
Normal file
9
migrations/001_create_users_table.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$pdo->exec("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,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
)");
|
||||
10
migrations/002_create_projects_table.php
Normal file
10
migrations/002_create_projects_table.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS projects (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
user_id INT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)");
|
||||
13
migrations/003_create_tasks_table.php
Normal file
13
migrations/003_create_tasks_table.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS tasks (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
project_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
status ENUM('created', 'in_progress', 'testing', 'complete', 'approved') DEFAULT 'created',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)");
|
||||
142
public/dashboard.html
Normal file
142
public/dashboard.html
Normal file
@@ -0,0 +1,142 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TaskIt! - Dashboard</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
background-color: #f4f6f9;
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
.dashboard-container {
|
||||
max-width: 1200px;
|
||||
margin: 2rem auto;
|
||||
}
|
||||
.project-card {
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
.project-card:hover {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
.task-status {
|
||||
font-size: 0.8rem;
|
||||
padding: 0.2rem 0.5rem;
|
||||
border-radius: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="#">TaskIt!</a>
|
||||
<button class="btn btn-outline-danger" id="logoutBtn">Logout</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="dashboard-container">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="card project-card mb-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Create New Project</h5>
|
||||
<form id="newProjectForm">
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" placeholder="Project Name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control" placeholder="Project Description" rows="3" required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Create Project</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8" id="projectList">
|
||||
<!-- Projects will be dynamically loaded here -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
// Check Authentication
|
||||
async function checkAuth() {
|
||||
const response = await fetch('/api/projects', {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
window.location.href = '/index.html';
|
||||
}
|
||||
}
|
||||
|
||||
// Logout Handler
|
||||
document.getElementById('logoutBtn').addEventListener('click', async () => {
|
||||
try {
|
||||
const response = await fetch('/api/logout', { method: 'POST' });
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
window.location.href = '/index.html';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Logout error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Load Projects
|
||||
async function loadProjects() {
|
||||
const projectList = document.getElementById('projectList');
|
||||
try {
|
||||
const response = await fetch('/api/projects');
|
||||
const projects = await response.json();
|
||||
|
||||
projectList.innerHTML = projects.map(project => `
|
||||
<div class="card project-card mb-3">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${project.name}</h5>
|
||||
<p class="card-text">${project.description}</p>
|
||||
<a href="/project.html?id=${project.id}" class="btn btn-outline-primary">View Tasks</a>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
} catch (error) {
|
||||
console.error('Projects load error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Create New Project
|
||||
document.getElementById('newProjectForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const name = this.querySelector('input[type="text"]').value;
|
||||
const description = this.querySelector('textarea').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/projects', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, description })
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result) {
|
||||
loadProjects();
|
||||
this.reset();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Project creation error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Initial Load
|
||||
checkAuth();
|
||||
loadProjects();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
132
public/index.html
Normal file
132
public/index.html
Normal file
@@ -0,0 +1,132 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TaskIt! - Project Management</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
background-color: #f4f6f9;
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
.auth-container {
|
||||
max-width: 400px;
|
||||
margin: 5rem auto;
|
||||
background-color: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
|
||||
padding: 2rem;
|
||||
}
|
||||
.dashboard-card {
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
.dashboard-card:hover {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" class="container-fluid">
|
||||
<!-- Login Screen -->
|
||||
<div id="loginScreen" class="auth-container text-center">
|
||||
<h2 class="mb-4">TaskIt!</h2>
|
||||
<form id="loginForm">
|
||||
<div class="mb-3">
|
||||
<input type="email" class="form-control" placeholder="Email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" class="form-control" placeholder="Password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
<p class="mt-3">Don't have an account? <a href="#" id="showRegister">Register</a></p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Registration Screen -->
|
||||
<div id="registerScreen" class="auth-container text-center" style="display:none;">
|
||||
<h2 class="mb-4">Create Account</h2>
|
||||
<form id="registerForm">
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" placeholder="Full Name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="email" class="form-control" placeholder="Email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" class="form-control" placeholder="Password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success w-100">Register</button>
|
||||
<p class="mt-3">Already have an account? <a href="#" id="showLogin">Login</a></p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
// Simple Auth UI Toggle
|
||||
document.getElementById('showRegister').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
document.getElementById('loginScreen').style.display = 'none';
|
||||
document.getElementById('registerScreen').style.display = 'block';
|
||||
});
|
||||
|
||||
document.getElementById('showLogin').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
document.getElementById('registerScreen').style.display = 'none';
|
||||
document.getElementById('loginScreen').style.display = 'block';
|
||||
});
|
||||
|
||||
// Authentication Handlers
|
||||
document.getElementById('loginForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const email = this.querySelector('input[type="email"]').value;
|
||||
const password = this.querySelector('input[type="password"]').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, password })
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
window.location.href = '/dashboard.html';
|
||||
} else {
|
||||
alert(result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('registerForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const name = this.querySelector('input[type="text"]').value;
|
||||
const email = this.querySelector('input[type="email"]').value;
|
||||
const password = this.querySelector('input[type="password"]').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, email, password })
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
window.location.href = '/dashboard.html';
|
||||
} else {
|
||||
alert(result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
151
public/index.php
Normal file
151
public/index.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../db.php';
|
||||
|
||||
use App\Controllers\AuthController;
|
||||
use App\Controllers\ProjectController;
|
||||
use App\Controllers\TaskController;
|
||||
|
||||
// Simple routing
|
||||
$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
// Serve HTML files for non-API routes
|
||||
if (!str_starts_with($requestUri, '/api/')) {
|
||||
switch ($requestUri) {
|
||||
case '/':
|
||||
case '/index.html':
|
||||
readfile(__DIR__ . '/index.html');
|
||||
exit;
|
||||
case '/dashboard.html':
|
||||
readfile(__DIR__ . '/dashboard.html');
|
||||
exit;
|
||||
case '/project.html':
|
||||
readfile(__DIR__ . '/project.html');
|
||||
exit;
|
||||
default:
|
||||
// Try to serve static file if it exists
|
||||
$filePath = __DIR__ . $requestUri;
|
||||
if (file_exists($filePath) && is_file($filePath)) {
|
||||
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
|
||||
$mimeTypes = [
|
||||
'css' => 'text/css',
|
||||
'js' => 'application/javascript',
|
||||
'json' => 'application/json',
|
||||
'png' => 'image/png',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'svg' => 'image/svg+xml',
|
||||
];
|
||||
if (isset($mimeTypes[$extension])) {
|
||||
header('Content-Type: ' . $mimeTypes[$extension]);
|
||||
}
|
||||
readfile($filePath);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Headers for JSON responses
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
switch (true) {
|
||||
case $requestUri === '/api/register' && $method === 'POST':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$authController = new AuthController();
|
||||
echo json_encode($authController->register(
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['password']
|
||||
));
|
||||
break;
|
||||
|
||||
case $requestUri === '/api/login' && $method === 'POST':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$authController = new AuthController();
|
||||
echo json_encode($authController->login(
|
||||
$data['email'],
|
||||
$data['password']
|
||||
));
|
||||
break;
|
||||
|
||||
case $requestUri === '/api/logout' && $method === 'POST':
|
||||
$authController = new AuthController();
|
||||
echo json_encode($authController->logout());
|
||||
break;
|
||||
|
||||
case $requestUri === '/api/projects' && $method === 'GET':
|
||||
if (!AuthController::isAuthenticated()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Unauthorized']);
|
||||
break;
|
||||
}
|
||||
$projectController = new ProjectController();
|
||||
echo json_encode($projectController->getUserProjects());
|
||||
break;
|
||||
|
||||
case $requestUri === '/api/projects' && $method === 'POST':
|
||||
if (!AuthController::isAuthenticated()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Unauthorized']);
|
||||
break;
|
||||
}
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$projectController = new ProjectController();
|
||||
echo json_encode($projectController->createProject(
|
||||
$data['name'],
|
||||
$data['description']
|
||||
));
|
||||
break;
|
||||
|
||||
case preg_match('/^\/api\/projects\/(\d+)$/', $requestUri, $matches) && $method === 'GET':
|
||||
if (!AuthController::isAuthenticated()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Unauthorized']);
|
||||
break;
|
||||
}
|
||||
$projectController = new ProjectController();
|
||||
echo json_encode($projectController->getProjectDetails($matches[1]));
|
||||
break;
|
||||
|
||||
case $requestUri === '/api/tasks' && $method === 'POST':
|
||||
if (!AuthController::isAuthenticated()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Unauthorized']);
|
||||
break;
|
||||
}
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$taskController = new TaskController();
|
||||
echo json_encode($taskController->createTask(
|
||||
$data['name'],
|
||||
$data['description'],
|
||||
$data['project_id'],
|
||||
$data['status'] ?? 'created'
|
||||
));
|
||||
break;
|
||||
|
||||
case preg_match('/^\/api\/tasks\/(\d+)\/status$/', $requestUri, $matches) && $method === 'PUT':
|
||||
if (!AuthController::isAuthenticated()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Unauthorized']);
|
||||
break;
|
||||
}
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$taskController = new TaskController();
|
||||
echo json_encode($taskController->updateTaskStatus(
|
||||
$matches[1],
|
||||
$data['status']
|
||||
));
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(404);
|
||||
echo json_encode(['error' => 'Not Found']);
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
}
|
||||
162
public/project.html
Normal file
162
public/project.html
Normal file
@@ -0,0 +1,162 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TaskIt! - Project Details</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
background-color: #f4f6f9;
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
.project-container {
|
||||
max-width: 1200px;
|
||||
margin: 2rem auto;
|
||||
}
|
||||
.task-card {
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
.task-card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
.status-created { background-color: #e9ecef; color: #6c757d; }
|
||||
.status-in_progress { background-color: #ffc107; color: white; }
|
||||
.status-testing { background-color: #17a2b8; color: white; }
|
||||
.status-complete { background-color: #28a745; color: white; }
|
||||
.status-approved { background-color: #007bff; color: white; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/dashboard.html">TaskIt!</a>
|
||||
<button class="btn btn-outline-danger" id="logoutBtn">Logout</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="project-container">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Create New Task</h5>
|
||||
<form id="newTaskForm">
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" placeholder="Task Name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control" placeholder="Task Description" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<select class="form-control" required>
|
||||
<option value="created">Created</option>
|
||||
<option value="in_progress">In Progress</option>
|
||||
<option value="testing">Testing</option>
|
||||
<option value="complete">Complete</option>
|
||||
<option value="approved">Approved</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Create Task</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div id="projectHeader" class="mb-4">
|
||||
<h2 id="projectName"></h2>
|
||||
<p id="projectDescription"></p>
|
||||
</div>
|
||||
<div id="taskList">
|
||||
<!-- Tasks will be dynamically loaded here -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const projectId = urlParams.get('id');
|
||||
|
||||
// Logout Handler
|
||||
document.getElementById('logoutBtn').addEventListener('click', async () => {
|
||||
try {
|
||||
const response = await fetch('/api/logout', { method: 'POST' });
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
window.location.href = '/index.html';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Logout error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Load Project Details
|
||||
async function loadProjectDetails() {
|
||||
try {
|
||||
const response = await fetch(`/api/projects/${projectId}`);
|
||||
const data = await response.json();
|
||||
|
||||
document.getElementById('projectName').textContent = data.project.name;
|
||||
document.getElementById('projectDescription').textContent = data.project.description;
|
||||
|
||||
const taskList = document.getElementById('taskList');
|
||||
taskList.innerHTML = data.tasks.map(task => `
|
||||
<div class="card task-card mb-3">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h5 class="card-title">${task.name}</h5>
|
||||
<p class="card-text">${task.description}</p>
|
||||
</div>
|
||||
<div class="task-status status-${task.status} px-2 py-1 rounded">
|
||||
${task.status.replace('_', ' ')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
} catch (error) {
|
||||
console.error('Project details load error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Create New Task
|
||||
document.getElementById('newTaskForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const name = this.querySelector('input[type="text"]').value;
|
||||
const description = this.querySelector('textarea').value;
|
||||
const status = this.querySelector('select').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/tasks', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
description,
|
||||
project_id: projectId,
|
||||
status
|
||||
})
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result) {
|
||||
loadProjectDetails();
|
||||
this.reset();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Task creation error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Initial Load
|
||||
loadProjectDetails();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
54
src/Controllers/AuthController.php
Normal file
54
src/Controllers/AuthController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
session_start();
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class AuthController {
|
||||
private $userModel;
|
||||
|
||||
public function __construct() {
|
||||
$this->userModel = new User();
|
||||
}
|
||||
|
||||
public function register($name, $email, $password) {
|
||||
if ($this->userModel->findByEmail($email)) {
|
||||
return ['error' => 'Email already exists'];
|
||||
}
|
||||
|
||||
$result = $this->userModel->register($name, $email, $password);
|
||||
|
||||
if ($result) {
|
||||
$user = $this->userModel->findByEmail($email);
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
return ['success' => true, 'user' => $user];
|
||||
}
|
||||
|
||||
return ['error' => 'Registration failed'];
|
||||
}
|
||||
|
||||
public function login($email, $password) {
|
||||
$user = $this->userModel->login($email, $password);
|
||||
|
||||
if ($user) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
return ['success' => true, 'user' => $user];
|
||||
}
|
||||
|
||||
return ['error' => 'Invalid credentials'];
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
session_destroy();
|
||||
return ['success' => true];
|
||||
}
|
||||
|
||||
public static function isAuthenticated() {
|
||||
return isset($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
public static function getCurrentUserId() {
|
||||
return $_SESSION['user_id'] ?? null;
|
||||
}
|
||||
}
|
||||
36
src/Controllers/ProjectController.php
Normal file
36
src/Controllers/ProjectController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\Task;
|
||||
|
||||
class ProjectController {
|
||||
private $projectModel;
|
||||
private $taskModel;
|
||||
|
||||
public function __construct() {
|
||||
$this->projectModel = new Project();
|
||||
$this->taskModel = new Task();
|
||||
}
|
||||
|
||||
public function createProject($name, $description) {
|
||||
$userId = AuthController::getCurrentUserId();
|
||||
return $this->projectModel->create($name, $description, $userId);
|
||||
}
|
||||
|
||||
public function getUserProjects() {
|
||||
$userId = AuthController::getCurrentUserId();
|
||||
return $this->projectModel->getUserProjects($userId);
|
||||
}
|
||||
|
||||
public function getProjectDetails($projectId) {
|
||||
$userId = AuthController::getCurrentUserId();
|
||||
$project = $this->projectModel->getProjectById($projectId, $userId);
|
||||
$tasks = $this->taskModel->getProjectTasks($projectId);
|
||||
|
||||
return [
|
||||
'project' => $project,
|
||||
'tasks' => $tasks
|
||||
];
|
||||
}
|
||||
}
|
||||
21
src/Controllers/TaskController.php
Normal file
21
src/Controllers/TaskController.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Task;
|
||||
|
||||
class TaskController {
|
||||
private $taskModel;
|
||||
|
||||
public function __construct() {
|
||||
$this->taskModel = new Task();
|
||||
}
|
||||
|
||||
public function createTask($name, $description, $projectId, $status = 'created') {
|
||||
$userId = AuthController::getCurrentUserId();
|
||||
return $this->taskModel->create($name, $description, $projectId, $userId, $status);
|
||||
}
|
||||
|
||||
public function updateTaskStatus($taskId, $status) {
|
||||
return $this->taskModel->updateTaskStatus($taskId, $status);
|
||||
}
|
||||
}
|
||||
31
src/Models/Project.php
Normal file
31
src/Models/Project.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
require_once __DIR__ . '/../../db.php';
|
||||
|
||||
class Project {
|
||||
private $pdo;
|
||||
|
||||
public function __construct() {
|
||||
global $pdo;
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function create($name, $description, $userId) {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO projects (name, description, user_id) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$name, $description, $userId]);
|
||||
return $this->pdo->lastInsertId();
|
||||
}
|
||||
|
||||
public function getUserProjects($userId) {
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM projects WHERE user_id = ? ORDER BY created_at DESC");
|
||||
$stmt->execute([$userId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function getProjectById($projectId, $userId) {
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM projects WHERE id = ? AND user_id = ?");
|
||||
$stmt->execute([$projectId, $userId]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
}
|
||||
30
src/Models/Task.php
Normal file
30
src/Models/Task.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
require_once __DIR__ . '/../../db.php';
|
||||
|
||||
class Task {
|
||||
private $pdo;
|
||||
|
||||
public function __construct() {
|
||||
global $pdo;
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function create($name, $description, $projectId, $userId, $status = 'created') {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO tasks (name, description, project_id, user_id, status) VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $description, $projectId, $userId, $status]);
|
||||
return $this->pdo->lastInsertId();
|
||||
}
|
||||
|
||||
public function getProjectTasks($projectId) {
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM tasks WHERE project_id = ? ORDER BY created_at DESC");
|
||||
$stmt->execute([$projectId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function updateTaskStatus($taskId, $status) {
|
||||
$stmt = $this->pdo->prepare("UPDATE tasks SET status = ? WHERE id = ?");
|
||||
return $stmt->execute([$status, $taskId]);
|
||||
}
|
||||
}
|
||||
37
src/Models/User.php
Normal file
37
src/Models/User.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
require_once __DIR__ . '/../../db.php';
|
||||
|
||||
class User {
|
||||
private $pdo;
|
||||
|
||||
public function __construct() {
|
||||
global $pdo;
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function register($name, $email, $password) {
|
||||
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
|
||||
|
||||
$stmt = $this->pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
|
||||
return $stmt->execute([$name, $email, $hashedPassword]);
|
||||
}
|
||||
|
||||
public function login($email, $password) {
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
return $user;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function findByEmail($email) {
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user