Improve setup script
This commit is contained in:
parent
c6831ff032
commit
b7c15dc15b
48
setup.php
48
setup.php
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This script will create a local administrator account.
|
* This script will create a local administrator account.
|
||||||
*/
|
*/
|
||||||
@ -13,33 +12,28 @@ 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>
|
<title>Admin Account Creation</title>
|
||||||
<head>
|
<h1>Admin Account Creation tool</h1>
|
||||||
<title>Admin Account Creation</title>
|
<form action="setup.php" method="POST">
|
||||||
</head>
|
Username: <input type="text" name="username" placeholder="Username" required="required" /><br />
|
||||||
<body>
|
Password: <input type="text" name="password" placeholder="Password" required="required" /><br />
|
||||||
<h1>Admin Account Creation tool</h1>
|
Name: <input type="text" name="realname" placeholder="Real Name" required="required" /><br />
|
||||||
<form action="setup.php" method="POST">
|
Email: <input type="email" name="email" placeholder="Email Address" /><br />
|
||||||
Username: <input type="text" name="username" placeholder="Username" required="required" /><br />
|
<button type="submit">
|
||||||
Password: <input type="text" name="password" placeholder="Password" required="required" /><br />
|
Create account
|
||||||
Name: <input type="text" name="realname" placeholder="Real Name" required="required" /><br />
|
</button>
|
||||||
Email: <input type="email" name="email" placeholder="Email Address" /><br />
|
</form>
|
||||||
<button type="submit">
|
<?php
|
||||||
Create account
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
<?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]);
|
$database->insert('assigned_permissions', ['uid' => $userid, 'permid' => 1]);
|
||||||
die("Account created.");
|
die("ADMIN permission assigned.");
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user