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
*/
if ($user->power < $this->power) {
if ($user && $user->power < $this->power) {
header('Location: /?page=power&required=' . $this->power);
die();
}

View file

@ -9,7 +9,7 @@
use wishthis\{Page, Database};
if ($options && $options->getOption('isInstalled')) {
header('Location: /?page=login');
header('Location: /?page=home');
die();
}
@ -20,6 +20,7 @@ $step = isset($_POST['step']) ? $_POST['step'] : 1;
switch ($step) {
case 1:
session_destroy();
?>
<main>
<div class="ui hidden divider"></div>
@ -99,9 +100,11 @@ switch ($step) {
* Users
*/
$database->query('CREATE TABLE `users` (
`id` int PRIMARY KEY AUTO_INCREMENT,
`email` varchar(64) NOT NULL UNIQUE,
`password` varchar(128) NOT NULL
`id` int PRIMARY KEY AUTO_INCREMENT,
`email` varchar(64) NOT NULL UNIQUE,
`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`);');
@ -150,7 +153,7 @@ switch ($step) {
<div class="ui container">
<div class="ui segment">
<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>
</main>

View file

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

View file

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