Improve installer

This commit is contained in:
Jay Trees 2022-01-18 14:37:35 +01:00
parent ec4fafd5c0
commit 9be643d49a
4 changed files with 18 additions and 13 deletions

View file

@ -41,7 +41,7 @@ class Page
/** /**
* Power * Power
*/ */
if ($user->power < $this->power) { if ($user && $user->power < $this->power) {
header('Location: /?page=power&required=' . $this->power); header('Location: /?page=power&required=' . $this->power);
die(); die();
} }

View file

@ -9,7 +9,7 @@
use wishthis\{Page, Database}; use wishthis\{Page, Database};
if ($options && $options->getOption('isInstalled')) { if ($options && $options->getOption('isInstalled')) {
header('Location: /?page=login'); header('Location: /?page=home');
die(); die();
} }
@ -20,6 +20,7 @@ $step = isset($_POST['step']) ? $_POST['step'] : 1;
switch ($step) { switch ($step) {
case 1: case 1:
session_destroy();
?> ?>
<main> <main>
<div class="ui hidden divider"></div> <div class="ui hidden divider"></div>
@ -99,9 +100,11 @@ switch ($step) {
* Users * Users
*/ */
$database->query('CREATE TABLE `users` ( $database->query('CREATE TABLE `users` (
`id` int PRIMARY KEY AUTO_INCREMENT, `id` int PRIMARY KEY AUTO_INCREMENT,
`email` varchar(64) NOT NULL UNIQUE, `email` varchar(64) NOT NULL UNIQUE,
`password` varchar(128) NOT NULL `password` varchar(128) NOT NULL,
`last_login` datetime NOT NULL DEFAULT NOW(),
`power` int NOT NULL DEFAULT 0
);'); );');
$database->query('CREATE INDEX `idx_password` ON `users` (`password`);'); $database->query('CREATE INDEX `idx_password` ON `users` (`password`);');
@ -150,7 +153,7 @@ switch ($step) {
<div class="ui container"> <div class="ui container">
<div class="ui segment"> <div class="ui segment">
<h1 class="ui header">Success</h1> <h1 class="ui header">Success</h1>
<p><a class="ui primary button" href="/?page=register">Login</a></p> <p><a class="ui primary button" href="/?page=register">Register</a></p>
</div> </div>
</div> </div>
</main> </main>

View file

@ -19,8 +19,8 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) {
/** Current version is below 0.2.0 */ /** Current version is below 0.2.0 */
if (-1 === version_compare($options->version, '0.2.0')) { if (-1 === version_compare($options->version, '0.2.0')) {
$database->query('ALTER TABLE `users` $database->query('ALTER TABLE `users`
ADD `last_login` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `password`, ADD `last_login` DATETIME NOT NULL DEFAULT NOW() AFTER `password`,
ADD `power` BOOLEAN NOT NULL DEFAULT 0 AFTER `last_login` ADD `power` BOOLEAN NOT NULL DEFAULT 0 AFTER `last_login`
;'); ;');
$database->query('UPDATE `users` $database->query('UPDATE `users`
SET `power` = 100 SET `power` = 100

View file

@ -53,11 +53,6 @@ if (
*/ */
session_start(); session_start();
/**
* User
*/
$user = new wishthis\User();
/** /**
* API * API
*/ */
@ -72,6 +67,13 @@ if (!$options) {
$page = 'install'; $page = 'install';
} }
/**
* User
*/
if ($options) {
$user = new wishthis\User();
}
/** /**
* Update * Update
*/ */