Merge branch 'develop' into stable

This commit is contained in:
Jay Trees 2022-01-18 14:46:17 +01:00
commit ee9b8c9d11
4 changed files with 24 additions and 15 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,10 +100,13 @@ 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 INDEX
`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`);');
/**
* Wishlists
@ -111,10 +115,12 @@ switch ($step) {
`id` int PRIMARY KEY AUTO_INCREMENT,
`user` int NOT NULL,
`name` varchar(128) NOT NULL,
`hash` varchar(128) NOT NULL,
FOREIGN KEY (`user`)
REFERENCES `users` (`id`)
ON DELETE CASCADE
);');
$database->query('CREATE INDEX `idx_hash` ON `wishlists` (`hash`);');
/**
* Products
@ -122,7 +128,7 @@ switch ($step) {
$database->query('CREATE TABLE `products` (
`id` int NOT NULL PRIMARY KEY AUTO_INCREMENT,
`wishlist` int NOT NULL,
`hash` VARCHAR(255) NOT NULL INDEX,
`url` VARCHAR(255) NOT NULL,
FOREIGN KEY (`wishlist`)
REFERENCES `wishlists` (`id`)
ON DELETE CASCADE
@ -139,7 +145,8 @@ switch ($step) {
$database->query('INSERT INTO `options`
(`key`, `value`) VALUES
("isInstalled", true)
("isInstalled", true),
("version", "' . VERSION . '")
;');
?>
<main>
@ -147,7 +154,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
*/