114 lines
3.5 KiB
PHP
114 lines
3.5 KiB
PHP
<?php
|
|
global $c;
|
|
|
|
try
|
|
{
|
|
$intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"];
|
|
|
|
if ($intUserCount < 1)
|
|
{
|
|
BootstrapRender::message(
|
|
"Please create an administrator account.",
|
|
"warning");
|
|
}
|
|
|
|
if (Request::posts("email", "password", "repeat"))
|
|
{
|
|
$strEmail = Request::getPosted("email");
|
|
$strPassword = Request::getPosted("password");
|
|
$strRepeat = Request::getPosted("repeat");
|
|
|
|
if (!preg_match("/^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$/", $strEmail))
|
|
throw new Exception("Not a valid e-mail address");
|
|
|
|
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 credentials where email like ?", $strEmail);
|
|
|
|
if (count($varUsers) > 0)
|
|
throw new Exception("E-mail address in use");
|
|
|
|
$strHash = sha1($strPassword);
|
|
|
|
$c->query(
|
|
"INSERT into credentials (email, hash) values (?, ?)",
|
|
$strEmail,
|
|
$strHash);
|
|
|
|
$intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"];
|
|
|
|
if ($intUserCount == 1)
|
|
{
|
|
$c->query(
|
|
"INSERT into permissions (email, permission) values (?, ?)",
|
|
$strEmail,
|
|
"admin");
|
|
}
|
|
|
|
BootstrapRender::message("Registration was a success, please sign in to continue.");
|
|
|
|
Respond::redirect("/user/signin");
|
|
}
|
|
|
|
}
|
|
catch (Exception $x)
|
|
{
|
|
BootstrapRender::message($x->getMessage(), "danger");
|
|
}
|
|
?>
|
|
|
|
<script>
|
|
$(".app-header").hide();
|
|
</script>
|
|
|
|
<div class="container">
|
|
<div class="row my-5">
|
|
<div class="col-md-4 offset-md-4">
|
|
|
|
<?php BootstrapRender::message(); ?>
|
|
|
|
<form method="post">
|
|
|
|
<?php BootstrapRender::input([
|
|
"name" => "email",
|
|
"label" => "E-Mail Address",
|
|
"value" => Request::getPosted("email")
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::input([
|
|
"name" => "password",
|
|
"label" => "Password",
|
|
"value" => Request::getPosted("password"),
|
|
"type" => "password",
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::input([
|
|
"name" => "repeat",
|
|
"label" => "Repeat Password",
|
|
"value" => Request::getPosted("repeat"),
|
|
"type" => "password",
|
|
]); ?>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Actions</label>
|
|
<div class="input-group">
|
|
<button class="btn btn-outline-primary" type="submit">
|
|
<i class="fa fa-fw fa-right-to-bracket"></i>
|
|
<span>Continue</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<a class="text-decoration-none" href="/user/signin">Already have an account?</a>
|
|
</div>
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|