diff --git a/auth/login_handler.php b/auth/login_handler.php new file mode 100644 index 0000000..9167766 --- /dev/null +++ b/auth/login_handler.php @@ -0,0 +1,37 @@ +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; + } +} diff --git a/auth/register_handler.php b/auth/register_handler.php new file mode 100644 index 0000000..7ae50c1 --- /dev/null +++ b/auth/register_handler.php @@ -0,0 +1,37 @@ +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; + } +} diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..d9effe1 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,28 @@ + + +
+ + diff --git a/db/create_db.php b/db/create_db.php new file mode 100644 index 0000000..7989563 --- /dev/null +++ b/db/create_db.php @@ -0,0 +1,18 @@ + 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"); +} + diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..7af8c16 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,12 @@ +exec($sql); + echo "Database migration successful!\n"; +} catch (PDOException $e) { + die("Database migration failed: " . $e->getMessage() . "\n"); +} + diff --git a/db/migrations/001_initial_schema.sql b/db/migrations/001_initial_schema.sql new file mode 100644 index 0000000..37853e7 --- /dev/null +++ b/db/migrations/001_initial_schema.sql @@ -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; + diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..b5a6a90 --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,6 @@ + + +