From e9a01ca6619ceeb9b408192de8c56cbcbde066aa Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 2 Nov 2025 14:43:46 +0000 Subject: [PATCH] leveling project --- assets/css/custom.css | 91 +++++++++++++++++ assets/js/main.js | 0 dashboard.php | 49 +++++++++ db/config.php | 49 ++++++--- db/setup.php | 35 +++++++ includes/footer.php | 13 +++ includes/header.php | 53 ++++++++++ index.php | 225 +++++++++++++++--------------------------- login.php | 44 +++++++++ logout.php | 22 +++++ register.php | 54 ++++++++++ 11 files changed, 476 insertions(+), 159 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 assets/js/main.js create mode 100644 dashboard.php create mode 100644 db/setup.php create mode 100644 includes/footer.php create mode 100644 includes/header.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 register.php diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..31e9544 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,91 @@ +:root { + --primary-color: #4F46E5; + --secondary-color: #10B981; + --dark-color: #111827; + --surface-color: #1F2937; + --text-color: #F9FAFB; +} + +body { + font-family: 'Inter', sans-serif; + background-color: var(--dark-color); + color: var(--text-color); +} + +h1, h2, h3, h4, h5, h6, .navbar-brand { + font-family: 'Orbitron', sans-serif; +} + +.bg-dark { + background-color: var(--dark-color) !important; +} + +.bg-surface { + background-color: var(--surface-color) !important; +} + +.card { + border: 1px solid rgba(255, 255, 255, 0.1); + border-radius: 0.5rem; + transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; +} + +.card:hover { + transform: translateY(-5px); + box-shadow: 0 10px 20px rgba(0,0,0,0.2); +} + +.form-control { + background-color: #374151; + border: 1px solid #4B5563; + color: var(--text-color); + border-radius: 0.375rem; +} + +.form-control:focus { + background-color: #374151; + color: var(--text-color); + border-color: var(--primary-color); + box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25); +} + +.btn-primary { + background-color: var(--primary-color); + border-color: var(--primary-color); + font-weight: bold; + transition: background-color 0.2s; +} + +.btn-primary:hover { + background-color: #4338CA; + border-color: #4338CA; +} + +.btn-secondary { + background-color: var(--secondary-color); + border-color: var(--secondary-color); + font-weight: bold; + transition: background-color 0.2s; +} + +.btn-secondary:hover { + background-color: #059669; + border-color: #059669; +} + +.hero-section { + padding: 4rem 0; +} + +.navbar-dark .navbar-brand { + color: var(--primary-color); + font-weight: bold; +} + +.navbar-dark .nav-link { + color: rgba(255,255,255,.7); +} + +.navbar-dark .nav-link:hover, .navbar-dark .nav-link.active { + color: #fff; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..e69de29 diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..82a8a23 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,49 @@ +prepare("SELECT * FROM users WHERE id = ?"); + $stmt->execute([$_SESSION['user_id']]); + $user = $stmt->fetch(); +} catch (PDOException $e) { + // Handle error, maybe redirect or show a message + $user = null; +} + +?> + +
+

Welcome, !

+ +
+
+

Your Status

+ +

Level:

+

XP:

+

Role:

+ +

Could not load user data.

+ +
+
+ +
+

Your journey continues...

+

Learning Kits and Achievements are coming soon!

+
+
+ + + \ No newline at end of file diff --git a/db/config.php b/db/config.php index f12ebaf..45c9b30 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,40 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; +// Create the database if it doesn't exist +try { + $pdo_init = new PDO("mysql:host=" . DB_HOST, DB_USER, DB_PASS); + $pdo_init->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $pdo_init->exec("CREATE DATABASE IF NOT EXISTS `" . DB_NAME . "`"); + $pdo_init = null; +} catch(PDOException $e) { + // Don't die, the main connection will handle it } + +function db(): PDO { + static $pdo; + if ($pdo) { + return $pdo; + } + + $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET; + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + try { + $pdo = new PDO($dsn, DB_USER, DB_PASS, $options); + return $pdo; + } catch (PDOException $e) { + // In a real app, you'd log this error. + // For this setup, we'll just show a generic error. + die('Database connection failed. Please check config and ensure MySQL is running.'); + } +} +?> \ No newline at end of file diff --git a/db/setup.php b/db/setup.php new file mode 100644 index 0000000..a643d82 --- /dev/null +++ b/db/setup.php @@ -0,0 +1,35 @@ +exec($sql); + + // Optional: Create a default admin user if one doesn't exist + $stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'admin'"); + $stmt->execute(); + if ($stmt->rowCount() == 0) { + $admin_pass = 'admin123'; // Super secure default password + $admin_hash = password_hash($admin_pass, PASSWORD_DEFAULT); + $admin_sql = "INSERT INTO users (username, password_hash, user_role) VALUES ('admin', ?, 'admin')"; + $admin_stmt = $pdo->prepare($admin_sql); + $admin_stmt->execute([$admin_hash]); + echo "Default admin user created with username 'admin' and password 'admin123'.
"; + } + + echo "Database setup completed successfully!"; + +} catch (PDOException $e) { + die("Database setup failed: " . $e->getMessage()); +} +?> \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..924b783 --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..86ab3bb --- /dev/null +++ b/includes/header.php @@ -0,0 +1,53 @@ + + + + + + + Solo Leveling: IT + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..ea53b16 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,83 @@ - - - - - - New Style - - - - - - - - - - - - - - - - - - - - - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
+

Level Up Your IT Skills

+

Join quests, conquer challenges, and rise through the ranks. Your journey to becoming an IT master starts now.

+
+ +
+ +
+
+
+

Player Login

+ +
Invalid username or password.
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+
-
-
- Page updated: (UTC) -
- - + + +
+
+
+

New Player

+ +
+ + +
Registration successful! Please log in.
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+ + + diff --git a/login.php b/login.php new file mode 100644 index 0000000..0beff24 --- /dev/null +++ b/login.php @@ -0,0 +1,44 @@ +prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password_hash'])) { + // Password is correct, start session + session_regenerate_id(); + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + $_SESSION['user_role'] = $user['user_role']; + + header('Location: dashboard.php'); + exit(); + } else { + // Invalid credentials + header('Location: index.php?login_error=1#login'); + exit(); + } + +} catch (PDOException $e) { + // In a real app, log the error + header('Location: index.php?login_error=1#login'); + exit(); +} +?> \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..d1d29a0 --- /dev/null +++ b/logout.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/register.php b/register.php new file mode 100644 index 0000000..ff5172e --- /dev/null +++ b/register.php @@ -0,0 +1,54 @@ +prepare("SELECT id FROM users WHERE username = ?"); + $stmt->execute([$username]); + if ($stmt->rowCount() > 0) { + header('Location: index.php?reg_error=Username already taken.#register'); + exit(); + } + + // Hash password and insert user + $password_hash = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (username, password_hash) VALUES (?, ?)"); + $stmt->execute([$username, $password_hash]); + + header('Location: index.php?reg_success=1#login'); + exit(); + +} catch (PDOException $e) { + // In a real app, log the error + header('Location: index.php?reg_error=A database error occurred.#register'); + exit(); +} +?> \ No newline at end of file