Set default administrator
This commit is contained in:
parent
a82694c863
commit
e259acbd4f
2 changed files with 17 additions and 4 deletions
|
@ -11,10 +11,19 @@ use wishthis\Page;
|
||||||
$page = new page(__FILE__, 'Register');
|
$page = new page(__FILE__, 'Register');
|
||||||
|
|
||||||
if (isset($_POST['email'], $_POST['password'])) {
|
if (isset($_POST['email'], $_POST['password'])) {
|
||||||
$database->query('INSERT INTO `users`
|
$users = $database->query('SELECT * FROM `users`;')->fetchAll();
|
||||||
(`email`, `password`) VALUES
|
|
||||||
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '")
|
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');
|
header('Location: /?page=login');
|
||||||
die();
|
die();
|
||||||
|
|
|
@ -24,6 +24,10 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) {
|
||||||
ADD `last_login` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `password`,
|
ADD `last_login` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `password`,
|
||||||
ADD `isAdministrator` BOOLEAN NOT NULL AFTER `last_login`
|
ADD `isAdministrator` BOOLEAN NOT NULL AFTER `last_login`
|
||||||
;');
|
;');
|
||||||
|
$database->query('UPDATE `users`
|
||||||
|
SET `isAdministrator` = ' . true . '
|
||||||
|
WHERE `id` = ' . $user->id .
|
||||||
|
';');
|
||||||
|
|
||||||
$database->query('ALTER TABLE `wishlists`
|
$database->query('ALTER TABLE `wishlists`
|
||||||
ADD `url` VARCHAR(128) NOT NULL AFTER `name`
|
ADD `url` VARCHAR(128) NOT NULL AFTER `name`
|
||||||
|
|
Loading…
Reference in a new issue