88 lines
2.6 KiB
PHP
88 lines
2.6 KiB
PHP
<?php
|
|
global $c;
|
|
|
|
try
|
|
{
|
|
$intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"];
|
|
|
|
if ($intUserCount < 1)
|
|
Respond::redirect("/user/register");
|
|
|
|
if (Request::posts("email", "password"))
|
|
{
|
|
$strEmail = Request::getPosted("email");
|
|
$strPassword = Request::getPosted("password");
|
|
$strHash = sha1($strPassword);
|
|
$varUsers = $c->query(
|
|
"SELECT *
|
|
from credentials
|
|
where
|
|
email like ?
|
|
and hash = ?",
|
|
$strEmail,
|
|
$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 (email, token) values (?, ?)",
|
|
$strEmail,
|
|
$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" => "email",
|
|
"label" => "E-Mail Address",
|
|
"value" => Request::getPosted("email")
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::input([
|
|
"name" => "password",
|
|
"label" => "Password",
|
|
"value" => Request::getPosted("password"),
|
|
"type" => "password",
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::buttons([
|
|
"input_group" => 0,
|
|
"buttons" => [
|
|
["icon" => "right-to-bracket", "label" => "Continue", "type" => "submit", "class" => "outline-primary"],
|
|
["icon" => "home", "label" => "Home", "href" => "/"]
|
|
]]); ?>
|
|
|
|
<div class="mb-3">
|
|
<a class="text-decoration-none" href="/user/register">Don't have an account?</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|