Dragon-Knight/public/install/doodie.php

39 lines
1.4 KiB
PHP

<?php // install.php :: creates/populates database tables on a new installation.
// Admin account; create it from the provided info
if ($step == 'third') {
$errors = [];
// Make sure our info is at least mostly valid
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.';
}
}
// Make sure the class selection is valid
$class = isset($_POST['class']) && in_array($_POST['class'], [1, 2, 3]) ? $_POST['class'] : 1;
// If we have any errors, bail to the form and let the user know
if (!empty($errors)) {
echo render('install/layout', ['title' => 'Admin Account', 'step' => 'third', 'errors' => $errors, 'complete' => $_POST['complete'] ?? false]);
exit;
}
// Create the .installed file in the server folder
file_put_contents(SERVER.'/.installed', 'Installed on '.date('Y-m-d H:i:s'));
// Create the admin account
createUser($_POST['username'], $_POST['password'], $_POST['email'], $class, ['role' => 5, 'verified' => 1]);
// Render the finished page!
echo render('install/layout', ['title' => 'Finished!', 'step' => 'done', 'name' => $_POST['username'], 'complete' => $_POST['complete'] ?? false]);
exit;
}