1
0
Fork 0
app.sixfold.org/www/login.php

58 lines
1.9 KiB
PHP

<?php
if (isset($_SESSION["account"]->id)) {
http_response_code(303);
header("Location: /");
die();
}
$description = "Log in to access your account.";
$title = "Login";
if ($_SERVER["REQUEST_METHOD"] === "POST"): ?>
<?php
$stmt = $db["data"]->prepare("SELECT * FROM members WHERE LOWER(email) = LOWER(:email)");
$results = $stmt->execute([
"email" => $_POST["email"],
]);
$account = $stmt->fetch(PDO::FETCH_OBJ);
if (!$account) {
http_response_code(401);
} elseif (password_check($account)) {
$_SESSION["account"] = $account;
http_response_code(303);
header("Location: " . $_POST["redirect"] ?? "/");
die();
}
endif;
include "partials/head.php";
?>
<body>
<?php include "partials/header.php"; ?>
<main id="main" class="flow">
<header>
<h1><?= $title ?></h1>
</header>
<?php if (isset($_SESSION["alert_message"])) { ?>
<aside class="alert">
<p><?= $_SESSION["alert_message"] ?></p>
<?php unset($_SESSION["alert_message"]); ?>
</aside>
<?php } ?>
<?php if (!COOKIES_ENABLED && $_SERVER["REQUEST_METHOD"] === "POST") { ?>
<aside class='alert'>
<p>Your browser is not set to accept cookies. You cannot login or use certain portions of the site unless your browser accepts cookies. Please change your browser settings to accept cookies and try again. Thanks.</p>
</aside>
<?php } ?>
<?php if (http_response_code() === 401) { ?>
<aside class='alert'>
<p>Your email or password is incorrect.</p>
</aside>
<?php } ?>
<?php if (http_response_code() === 500) { ?>
<aside class='alert'>
<p>We encounterred an issue when processing your request; please try again.</p>
</aside>
<?php } ?>
<?php include "partials/login-form.php"; ?>
</main>
<?php include "partials/footer.php"; ?>