46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
include "config.php";
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
$u = $_POST["username"];
|
|
$p = $_POST["password"];
|
|
|
|
if ($u && $p) {
|
|
$response = pg_select(
|
|
$db,
|
|
"users",
|
|
array("username" => $u)
|
|
);
|
|
|
|
if (sizeof($response) === 0) {
|
|
$err = "User '" . htmlspecialchars($u) . "' not found";
|
|
} else {
|
|
echo json_encode($response);
|
|
}
|
|
} else {
|
|
$err = "Bad request, missing username or password parameter";
|
|
}
|
|
} else {
|
|
$u = "";
|
|
$p = "";
|
|
}
|
|
|
|
$title = "Log In";
|
|
include "boilerplate/head.php";
|
|
?>
|
|
|
|
<form method="POST">
|
|
<div><input placeholder="Username" name="username" value="<?php echo htmlspecialchars($u); ?>" maxlength="64" required></div>
|
|
<div><input placeholder="Password" name="password" type="password" value="<?php echo htmlspecialchars($p); ?>" required></div>
|
|
<div><input type="submit" value="Log in"></div>
|
|
</form>
|
|
|
|
<?php
|
|
$q = "SELECT count(*) FROM users LIMIT 1;";
|
|
|
|
if ($signups !== false || ($signups === false && pg_fetch_array(pg_query($db, $q))["count"] !== 0)) {
|
|
echo "<p><a href=\"signup.php\">Sign up instead?</a></p>";
|
|
}
|
|
|
|
include "boilerplate/foot.php";
|
|
?>
|