Set default administrator

This commit is contained in:
Jay Trees 2022-01-18 11:57:51 +01:00
parent a82694c863
commit e259acbd4f
2 changed files with 17 additions and 4 deletions

View file

@ -11,10 +11,19 @@ use wishthis\Page;
$page = new page(__FILE__, 'Register');
if (isset($_POST['email'], $_POST['password'])) {
$users = $database->query('SELECT * FROM `users`;')->fetchAll();
if (0 === count($users)) {
$database->query('INSERT INTO `users`
(`email`, `password`) VALUES
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '")
;');
} else {
$database->query('INSERT INTO `users`
(`email`, `password`, `isAdministrator`) VALUES
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '", ' . true . ')
;');
}
header('Location: /?page=login');
die();

View file

@ -24,6 +24,10 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) {
ADD `last_login` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `password`,
ADD `isAdministrator` BOOLEAN NOT NULL AFTER `last_login`
;');
$database->query('UPDATE `users`
SET `isAdministrator` = ' . true . '
WHERE `id` = ' . $user->id .
';');
$database->query('ALTER TABLE `wishlists`
ADD `url` VARCHAR(128) NOT NULL AFTER `name`