This commit is contained in:
Flatlogic Bot 2025-09-17 11:37:51 +00:00
parent 29eabb5172
commit 05d192f46f
13 changed files with 495 additions and 129 deletions

37
auth/login_handler.php Normal file
View File

@ -0,0 +1,37 @@
<?php
session_start();
require_once __DIR__ . '/../db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email) || empty($password)) {
header('Location: /login.php?error=invalid_input');
exit;
}
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id, password, role FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
// Password is correct, start session
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_role'] = $user['role'];
header('Location: /dashboard.php');
exit;
} else {
header('Location: /login.php?error=auth_failed');
exit;
}
} catch (PDOException $e) {
header('Location: /login.php?error=db_error');
exit;
}
}

37
auth/register_handler.php Normal file
View File

@ -0,0 +1,37 @@
<?php
require_once __DIR__ . '/../db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email) || empty($password) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
header('Location: /register.php?error=invalid_input');
exit;
}
try {
$pdo = db();
// Check if user exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
header('Location: /register.php?error=user_exists');
exit;
}
// Insert new user
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (email, password, role) VALUES (?, ?, ?)");
$stmt->execute([$email, $hashed_password, 'FREE_USER']);
header('Location: /login.php?success=registered');
exit;
} catch (PDOException $e) {
// In a real app, log this error.
header('Location: /register.php?error=db_error');
exit;
}
}

28
dashboard.php Normal file
View File

@ -0,0 +1,28 @@
<?php
session_start();
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header('Location: /login.php');
exit;
}
require_once __DIR__ . '/includes/header.php';
?>
<div class="dashboard-container">
<h2>Welcome to Your Dashboard</h2>
<p>Your role: <?php echo htmlspecialchars($_SESSION['user_role']); ?></p>
<div class="cv-management">
<h3>Your CVs</h3>
<p>You don't have any CVs yet.</p>
<a href="/create_cv.php" class="button">Create a New CV</a>
</div>
<a href="/logout.php">Logout</a>
</div>
<?php
require_once __DIR__ . '/includes/footer.php';
?>

18
db/create_db.php Normal file
View File

@ -0,0 +1,18 @@
<?php
require_once __DIR__ . '/config.php';
try {
// Connect to MySQL server without specifying a database
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
// Create the database if it doesn't exist
$pdo->exec("CREATE DATABASE IF NOT EXISTS `" . DB_NAME . "`");
echo "Database '" . DB_NAME . "' created successfully or already exists.\n";
} catch (PDOException $e) {
die("Database creation failed: " . $e->getMessage() . "\n");
}

12
db/migrate.php Normal file
View File

@ -0,0 +1,12 @@
<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
$sql = file_get_contents(__DIR__ . '/migrations/001_initial_schema.sql');
$pdo->exec($sql);
echo "Database migration successful!\n";
} catch (PDOException $e) {
die("Database migration failed: " . $e->getMessage() . "\n");
}

View File

@ -0,0 +1,43 @@
-- Initial Schema for MagiCV
-- Organizations table for multitenancy
CREATE TABLE IF NOT EXISTS `organizations` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Users table with roles
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`organization_id` INT NULL,
`email` VARCHAR(255) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`role` ENUM('GUEST', 'FREE_USER', 'PRO_USER', 'SUPER_ADMIN') NOT NULL DEFAULT 'FREE_USER',
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Templates for CVs
CREATE TABLE IF NOT EXISTS `templates` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`description` TEXT,
`is_pro` BOOLEAN NOT NULL DEFAULT FALSE,
`thumbnail_url` VARCHAR(255),
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- CVs table to store user resume data
CREATE TABLE IF NOT EXISTS `cvs` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`user_id` INT NOT NULL,
`template_id` INT,
`title` VARCHAR(255) NOT NULL,
`cv_data` JSON,
`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,
FOREIGN KEY (`template_id`) REFERENCES `templates`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

6
includes/footer.php Normal file
View File

@ -0,0 +1,6 @@
</main>
<footer>
<p>&copy; <?php echo date('Y'); ?> MagiCV. All rights reserved.</p>
</footer>
</body>
</html>

21
includes/header.php Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MagiCV</title>
<link rel="stylesheet" href="/public/css/style.css?v=<?php echo time(); ?>">
</head>
<body>
<header>
<nav>
<a href="/" class="logo">MagiCV</a>
<ul>
<li><a href="/#templates">Templates</a></li>
<li><a href="/#features">Features</a></li>
<li><a href="/login.php">Login</a></li>
<li><a href="/register.php" class="button">Sign Up</a></li>
</ul>
</nav>
</header>
<main>

171
index.php
View File

@ -1,131 +1,46 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
<?php require_once __DIR__ . '/includes/header.php'; ?>
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<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>
<section class="hero">
<h1>Create a CV that gets you hired</h1>
<p>MagiCV helps you build a professional, polished resume in minutes. Impress recruiters and land your dream job.</p>
<a href="/register.php" class="button">Create Your CV Now</a>
</section>
<section id="templates" class="templates">
<h2>Choose Your Template</h2>
<p>Stunning, professional templates for every industry. More coming soon!</p>
<div class="template-gallery">
<div class="template-card">
<img src="https://picsum.photos/seed/template-1/400/500" alt="CV Template 1">
<h3>Minimalist</h3>
</div>
<p class="hint">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 class="template-card">
<img src="https://picsum.photos/seed/template-2/400/500" alt="CV Template 2">
<h3>Modern</h3>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
</body>
</html>
<div class="template-card">
<img src="https://picsum.photos/seed/template-3/400/500" alt="CV Template 3">
<h3>Creative</h3>
</div>
</div>
</section>
<section id="features" class="features">
<h2>Features</h2>
<div class="feature-list">
<div class="feature-item">
<h3>Easy to Use</h3>
<p>Our intuitive editor makes it simple to create and update your CV.</p>
</div>
<div class="feature-item">
<h3>Professional Templates</h3>
<p>Choose from a library of beautifully designed templates.</p>
</div>
<div class="feature-item">
<h3>PDF Export</h3>
<p>Download your CV as a high-quality PDF, ready to send.</p>
</div>
</div>
</section>
<?php require_once __DIR__ . '/includes/footer.php'; ?>

29
login.php Normal file
View File

@ -0,0 +1,29 @@
<?php
require_once __DIR__ . '/includes/header.php';
?>
<div class="auth-container">
<h2>Login to Your Account</h2>
<?php if (isset($_GET['error'])): ?>
<p class="error">Invalid email or password.</p>
<?php endif; ?>
<?php if (isset($_GET['success'])): ?>
<p class="success">Registration successful! Please login.</p>
<?php endif; ?>
<form action="/auth/login_handler.php" method="POST">
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" class="button">Login</button>
</form>
<p>Don't have an account? <a href="/register.php">Register here</a>.</p>
</div>
<?php
require_once __DIR__ . '/includes/footer.php';
?>

6
logout.php Normal file
View File

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

171
public/css/style.css Normal file
View File

@ -0,0 +1,171 @@
/* Basic Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
line-height: 1.6;
background-color: #f9fafb;
color: #333;
}
main {
padding: 2rem;
}
/* Header and Navigation */
header {
background: #fff;
border-bottom: 1px solid #eaeaea;
padding: 1rem 2rem;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
nav .logo {
font-size: 1.5rem;
font-weight: bold;
text-decoration: none;
color: #333;
}
nav ul {
list-style: none;
display: flex;
align-items: center;
gap: 1.5rem;
}
nav a {
text-decoration: none;
color: #555;
font-weight: 500;
}
nav a.button {
background-color: #6c63ff;
color: #fff;
padding: 0.5rem 1rem;
border-radius: 5px;
transition: background-color 0.3s;
}
nav a.button:hover {
background-color: #524dff;
}
/* Footer */
footer {
text-align: center;
padding: 2rem;
background: #fff;
border-top: 1px solid #eaeaea;
margin-top: 2rem;
}
/* Landing Page Sections */
.hero {
text-align: center;
padding: 4rem 2rem;
background-color: #f0f2f5;
}
.hero h1 {
font-size: 3rem;
margin-bottom: 1rem;
}
.hero p {
font-size: 1.2rem;
margin-bottom: 2rem;
color: #555;
}
.templates, .features {
padding: 4rem 2rem;
text-align: center;
}
.template-gallery, .feature-list {
display: flex;
justify-content: center;
gap: 2rem;
margin-top: 2rem;
flex-wrap: wrap;
}
.template-card, .feature-item {
background: #fff;
border: 1px solid #eaeaea;
border-radius: 8px;
padding: 1.5rem;
width: 300px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.template-card img {
max-width: 100%;
border-radius: 5px;
margin-bottom: 1rem;
}
/* Auth Forms */
.auth-container {
max-width: 400px;
margin: 4rem auto;
padding: 2rem;
background: #fff;
border: 1px solid #eaeaea;
border-radius: 8px;
}
.auth-container h2 {
text-align: center;
margin-bottom: 1.5rem;
}
.form-group {
margin-bottom: 1rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
}
.form-group input {
width: 100%;
padding: 0.75rem;
border: 1px solid #ccc;
border-radius: 5px;
}
.auth-container .button {
width: 100%;
padding: 0.75rem;
border: none;
border-radius: 5px;
background-color: #6c63ff;
color: #fff;
font-size: 1rem;
cursor: pointer;
}
.auth-container p {
text-align: center;
margin-top: 1rem;
}
/* Dashboard */
.dashboard-container {
max-width: 800px;
margin: 2rem auto;
padding: 2rem;
}

43
register.php Normal file
View File

@ -0,0 +1,43 @@
<?php
require_once __DIR__ . '/includes/header.php';
?>
<div class="auth-container">
<h2>Create Your Account</h2>
<?php if (isset($_GET['error'])): ?>
<p class="error">
<?php
switch ($_GET['error']) {
case 'invalid_input':
echo 'Invalid input. Please check your email and password.';
break;
case 'user_exists':
echo 'User with this email already exists.';
break;
case 'db_error':
echo 'An error occurred. Please try again later.';
break;
default:
echo 'An unknown error occurred.';
break;
}
?>
</p>
<?php endif; ?>
<form action="/auth/register_handler.php" method="POST">
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" class="button">Register</button>
</form>
<p>Already have an account? <a href="/login.php">Login here</a>.</p>
</div>
<?php
require_once __DIR__ . '/includes/footer.php';
?>