Improve setup script

This commit is contained in:
Skylar Ittner 2017-11-28 17:13:34 -07:00
parent c6831ff032
commit b7c15dc15b

View File

@ -1,5 +1,4 @@
<?php <?php
/* /*
* This script will create a local administrator account. * This script will create a local administrator account.
*/ */
@ -13,11 +12,7 @@ if ($database->has('accounts', ["[>]assigned_permissions" => ["uid" => "uid"]],
if (is_empty($_POST['username']) || is_empty($_POST['password']) || is_empty($_POST['realname'])) { if (is_empty($_POST['username']) || is_empty($_POST['password']) || is_empty($_POST['realname'])) {
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html>
<head>
<title>Admin Account Creation</title> <title>Admin Account Creation</title>
</head>
<body>
<h1>Admin Account Creation tool</h1> <h1>Admin Account Creation tool</h1>
<form action="setup.php" method="POST"> <form action="setup.php" method="POST">
Username: <input type="text" name="username" placeholder="Username" required="required" /><br /> Username: <input type="text" name="username" placeholder="Username" required="required" /><br />
@ -28,18 +23,17 @@ if (is_empty($_POST['username']) || is_empty($_POST['password']) || is_empty($_P
Create account Create account
</button> </button>
</form> </form>
</body>
</html>
<?php <?php
} else { } else {
require_once __DIR__ . "/lib/login.php"; require_once __DIR__ . "/lib/login.php";
$userid = adduser($_POST['username'], header("Content-Type: text/plain");
$_POST['password'], if (user_exists($_POST['username'])) {
$_POST['realname'], $userid = $database->get('accounts', 'uid', ['username' => $_POST['username']]);
(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ? $_POST['email'] : null), echo "User already exists, skipping creation.\n";
"", } else {
"", $userid = adduser($_POST['username'], $_POST['password'], $_POST['realname'], (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ? $_POST['email'] : null), "", "", 1);
1); echo "User account #$userid created.\n";
$database->insert('assigned_permissions', ['uid' => $userid, 'permid' => 1]); }
die("Account created."); $database->insert('assigned_permissions', ['uid' => $userid, 'permid' => 1]);
die("ADMIN permission assigned.");
} }