diff --git a/public/css/dragon.css b/public/css/dragon.css index c60209c..892c043 100644 --- a/public/css/dragon.css +++ b/public/css/dragon.css @@ -26,6 +26,10 @@ body { } } +.text-red { + color: #d20f39; +} + .mb-1 { margin-bottom: 1rem; } diff --git a/public/install/index.php b/public/install/index.php index 5c292fa..5cfe0d6 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -7,7 +7,8 @@ if (installed()) redirect('/'); $db = new Database(DB); -const STEPS = ['first', 'second', 'third', 'fourth', 'fifth']; +// Define our pages and whitelist the request +const STEPS = ['first', 'second', 'third']; $step = isset($_GET['step']) && in_array($_GET['step'], STEPS) ? $_GET['step'] : 'first'; // Introduction; offer the user two options for installation; @@ -21,7 +22,7 @@ if ($step == 'first') { // Database setup; create tables and default data (if requested) if ($step == 'second') { $istart = microtime(true); // time the database setup - if (!isset($_POST['mode'])) redirect('/install/'); // dont run install if a button wasnt clicked + if (!required(['mode'])) redirect('/install/'); // dont run step two if a button wasnt clicked $complete = $_POST['mode'] == 'complete'; // complete or partial setup // Create Control table @@ -378,7 +379,7 @@ if ($step == 'second') { ['name' => 'Breath', 'type' => 1, 'mp' => 25, 'effect' => 'heal:self,50', 'icon' => 'breath.png'], ['name' => 'Revive', 'type' => 1, 'mp' => 50, 'effect' => 'heal:self,100', 'icon' => 'revive.png'], ['name' => 'Gaia', 'type' => 1, 'mp' => 75, 'effect' => 'heal:self,150', 'icon' => 'gaia.png' ], - + // Type 2 = damage ['name' => 'Slash', 'type' => 2, 'mp' => 5, 'effect' => 'damage:opp,10', 'icon' => 'slash.png' ], ['name' => 'Magic Missile', 'type' => 2, 'mp' => 12, 'effect' => 'damage:opp,35', 'icon' => 'missile.png' ], @@ -431,8 +432,8 @@ if ($step == 'second') { ]); } - // Create Users table - $db->table('users')->create([ + // Create Players table + $db->table('players')->create([ 'id INTEGER PRIMARY KEY', 'username TEXT NOT NULL', 'password TEXT NOT NULL', @@ -469,7 +470,7 @@ if ($step == 'second') { // Create Fights table $db->table('fights')->create([ 'id INTEGER PRIMARY KEY', - 'user_id INTEGER DEFAULT 1', + 'player_id INTEGER DEFAULT 1', 'monster_id INTEGER DEFAULT 1', 'turn INTEGER DEFAULT 1', 'user_hp INTEGER DEFAULT 0', @@ -484,6 +485,41 @@ if ($step == 'second') { 'monster_sleep INTEGER DEFAULT 0', ]); - echo render('install/layout', ['title' => 'Database', 'step' => 'second', 'complete' => $complete]); + echo render('install/layout', ['title' => 'Database Setup', 'step' => 'second', 'complete' => $complete, 'start' => $istart]); exit; } + +// Admin account; create it from the provided info +if ($step == 'third') { + $errors = []; + + if (!required(['username', 'password', 'email'])) { + $errors[] = 'All fields are required.'; + } else { + if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { + $errors[] = 'Invalid email address format.'; + } + + if (strlen($_POST['password']) < 6) { + $errors[] = 'Password must be at least 6 characters long.'; + } + } + + $class = isset($_POST['class']) && in_array($_POST['class'], [1, 2, 3]) ? $_POST['class'] : 0; + + if (!empty($errors)) { + echo render('install/layout', ['title' => 'Admin Account', 'step' => 'third', 'errors' => $errors, 'complete' => $_POST['complete'] ?? false]); + exit; + } + + $db->table('players')->insert([ + 'username' => trim($_POST['username']), + 'password' => password_hash($_POST['password'], PASSWORD_ARGON2ID), + 'email' => trim($_POST['email']), + 'class' => $class, + 'role' => 5 + ]); + + echo render('install/layout', ['title' => 'Finished!', 'step' => 'done', 'name' => $_POST['username'], 'complete' => $_POST['complete'] ?? false]); + exit; +} diff --git a/server/database/dragon.db-shm b/server/database/dragon.db-shm new file mode 100644 index 0000000..b38007b Binary files /dev/null and b/server/database/dragon.db-shm differ diff --git a/server/database/dragon.db-wal b/server/database/dragon.db-wal new file mode 100644 index 0000000..4e119a0 Binary files /dev/null and b/server/database/dragon.db-wal differ diff --git a/server/lib.php b/server/lib.php index e223f25..dd66d9c 100644 --- a/server/lib.php +++ b/server/lib.php @@ -1,5 +1,11 @@ '; + $r ? print_r($var) : var_dump($var); + echo ''; + exit; +} + function gettemplate($templatename) { // SQL query for the template. diff --git a/server/templates/install/done.php b/server/templates/install/done.php new file mode 100644 index 0000000..e0e5929 --- /dev/null +++ b/server/templates/install/done.php @@ -0,0 +1,14 @@ +
+ Congratulations, = $name ?>! Your installation is complete. Dragon Knight is ready to go. + All that's left is to log in and start playing. Once you've set the + classes in the admin panel, you can assign yourself one. +
+ + + ++ We'd love if you were to join the Sharkk community and let us know what you think! + @TODO +
\ No newline at end of file diff --git a/server/templates/install/partials/adminForm.php b/server/templates/install/partials/adminForm.php new file mode 100644 index 0000000..4ef4aad --- /dev/null +++ b/server/templates/install/partials/adminForm.php @@ -0,0 +1,31 @@ + diff --git a/server/templates/install/second.php b/server/templates/install/second.php index 47cb618..1121510 100644 --- a/server/templates/install/second.php +++ b/server/templates/install/second.php @@ -1,5 +1,6 @@If you're seeing this page with no errors, then database setup is complete! + It took about = stopwatch($start) ?> seconds.
@@ -21,32 +22,4 @@ panel. - += render('install/partials/adminForm', ['complete' => $complete]) ?> diff --git a/server/templates/install/third.php b/server/templates/install/third.php new file mode 100644 index 0000000..c2d7e9f --- /dev/null +++ b/server/templates/install/third.php @@ -0,0 +1,12 @@ ++ It looks like we encountered some errors with the info provided for your + admin account. Let's try that again. +
+ +' . $error . ''; +} +?> + += render('install/partials/adminForm', ['complete' => $complete]) ?>