97 lines
2.8 KiB
PHP
97 lines
2.8 KiB
PHP
<?php
|
|
global $c;
|
|
|
|
try
|
|
{
|
|
$intUserCount = $c->query("SELECT count(*) as c from users")[0]["c"];
|
|
|
|
if ($intUserCount < 1)
|
|
Respond::redirect("/user/register");
|
|
|
|
if (Request::posts("username", "password"))
|
|
{
|
|
$strUsername = Request::getPosted("username");
|
|
$strPassword = Request::getPosted("password");
|
|
$strHash = sha1($strPassword);
|
|
$varUsers = $c->query(
|
|
"SELECT *
|
|
from users
|
|
where
|
|
username like ?
|
|
and hash = ?",
|
|
$strUsername,
|
|
$strHash);
|
|
|
|
if (count($varUsers) !== 1)
|
|
throw new Exception("Zero or more than one user returned for credentials provided");
|
|
|
|
$strToken = sha1(microtime());
|
|
|
|
$c->query(
|
|
"INSERT into sessions (username, token) values (?, ?)",
|
|
$strUsername,
|
|
$strToken);
|
|
|
|
Cookie::set("token", $strToken);
|
|
|
|
BootstrapRender::message(
|
|
"Successfully signed in",
|
|
"info");
|
|
|
|
Respond::redirect("/user/info");
|
|
}
|
|
|
|
}
|
|
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" => "username",
|
|
"label" => "Username",
|
|
"value" => Request::getPosted("email")
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::input([
|
|
"name" => "password",
|
|
"label" => "Password",
|
|
"value" => Request::getPosted("password"),
|
|
"type" => "password",
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::buttons([
|
|
[
|
|
"tag" => "button",
|
|
"icon" => "right-to-bracket",
|
|
"label" => "Continue",
|
|
"type" => "submit",
|
|
"class" => "outline-primary"
|
|
],
|
|
[
|
|
"icon" => "home",
|
|
"label" => "Home",
|
|
"href" => "/",
|
|
"class" => "outline-secondary"
|
|
]
|
|
]); ?>
|
|
|
|
<div class="mb-3">
|
|
<a class="text-decoration-none" href="/user/register">Don't have an account?</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|