2024-07-01 20:53:23 -05:00
|
|
|
<?php // install.php :: creates/populates database tables on a new installation.
|
|
|
|
|
2024-07-02 09:34:38 -05:00
|
|
|
// Admin account; create it from the provided info
|
|
|
|
if ($step == 'third') {
|
|
|
|
$errors = [];
|
|
|
|
|
2024-07-02 10:04:20 -05:00
|
|
|
// Make sure our info is at least mostly valid
|
2024-07-02 09:34:38 -05:00
|
|
|
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.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 10:04:20 -05:00
|
|
|
// Make sure the class selection is valid
|
|
|
|
$class = isset($_POST['class']) && in_array($_POST['class'], [1, 2, 3]) ? $_POST['class'] : 1;
|
2024-07-02 09:34:38 -05:00
|
|
|
|
2024-07-02 10:04:20 -05:00
|
|
|
// If we have any errors, bail to the form and let the user know
|
2024-07-02 09:34:38 -05:00
|
|
|
if (!empty($errors)) {
|
|
|
|
echo render('install/layout', ['title' => 'Admin Account', 'step' => 'third', 'errors' => $errors, 'complete' => $_POST['complete'] ?? false]);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2024-07-02 10:04:20 -05:00
|
|
|
// 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]);
|
2024-07-02 09:34:38 -05:00
|
|
|
|
2024-07-02 10:04:20 -05:00
|
|
|
// Render the finished page!
|
2024-07-02 09:34:38 -05:00
|
|
|
echo render('install/layout', ['title' => 'Finished!', 'step' => 'done', 'name' => $_POST['username'], 'complete' => $_POST['complete'] ?? false]);
|
|
|
|
exit;
|
|
|
|
}
|