84 lines
2.4 KiB
PHP
84 lines
2.4 KiB
PHP
<?php
|
|
global $c;
|
|
|
|
try
|
|
{
|
|
$intUserCount = $c->query("SELECT count(*) as c from users")[0]["c"];
|
|
|
|
if ($intUserCount < 1)
|
|
{
|
|
PageRender::message(
|
|
"Please create an administrator account.",
|
|
"warning");
|
|
}
|
|
|
|
if (Request::posts("username", "password", "repeat"))
|
|
{
|
|
$strUsername = Request::getPosted("username");
|
|
$strPassword = Request::getPosted("password");
|
|
$strRepeat = Request::getPosted("repeat");
|
|
|
|
if (!preg_match("/^[A-Za-z0-9]{1,}$/", $strUsername))
|
|
throw new Exception("Not a valid username");
|
|
|
|
if (Request::getPosted("password") !== Request::getPosted("repeat"))
|
|
throw new Exception("Passwords do not match");
|
|
|
|
if (strlen($strPassword) < 6)
|
|
throw new Exception("Password must be at least 6 characters");
|
|
|
|
$varUsers = $c->query("SELECT * from users where username like ?", $strUsername);
|
|
|
|
if (count($varUsers) > 0)
|
|
throw new Exception("Username in use");
|
|
|
|
$strHash = sha1($strPassword);
|
|
|
|
$c->query(
|
|
"INSERT into users (username, hash) values (?, ?)",
|
|
$strUsername,
|
|
$strHash);
|
|
|
|
$intUserCount = $c->query("SELECT count(*) as c from users")[0]["c"];
|
|
|
|
if ($intUserCount == 1)
|
|
$c->query("UPDATE users set can_post = 1, is_admin = 1");
|
|
|
|
PageRender::message("Registration was a success, please sign in to continue.");
|
|
|
|
Respond::redirect("/user/signin");
|
|
}
|
|
|
|
}
|
|
catch (Exception $x)
|
|
{
|
|
PageRender::message($x->getMessage(), "danger");
|
|
}
|
|
?>
|
|
|
|
<form method="post">
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<td><label>Username</label></td>
|
|
<td><input type="text" name="username" value="" /></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><label>Password</label></td>
|
|
<td><input type="password" name="password" value="" /></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><label>Repeat</label></td>
|
|
<td><input type="password" name="repeat" value="" /></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td></td>
|
|
<td><input type="submit" value="Go" /></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</form>
|