2023-11-06 16:38:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ($_SESSION['auth']) {
|
2024-03-17 15:48:32 +00:00
|
|
|
header('Location: /profile');
|
2023-11-06 16:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($query['callback'])) {
|
|
|
|
$message = "You must sign in to continue.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$email = $_POST['email'];
|
|
|
|
$password = $_POST['password'];
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM accounts WHERE email = :email";
|
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute(array("email"=> $email));
|
|
|
|
$user = $stmt->fetch();
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
|
|
|
die ("Something happened: ". $e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password_verify($password, $user["password"])) {
|
|
|
|
$_SESSION["id"] = $user["id"];
|
|
|
|
$_SESSION["auth"] = true;
|
2024-02-17 12:04:47 +00:00
|
|
|
//
|
|
|
|
// print_r($_POST);
|
|
|
|
// echo(is_string($_POST['keep_logged_in']));
|
|
|
|
|
2024-03-02 12:41:57 +00:00
|
|
|
if (array_key_exists('keep_logged_in', $_POST)) {
|
|
|
|
if ($_POST['keep_logged_in'] == "on") {
|
|
|
|
$token = generate_cookie_access_token($user['id']);
|
2024-02-17 12:04:47 +00:00
|
|
|
// print_r($token);
|
2024-05-29 17:33:57 +00:00
|
|
|
setcookie("keep_me_logged_in", $token['access'], time()+606024*365);
|
2024-03-02 12:41:57 +00:00
|
|
|
}
|
2024-02-17 12:04:47 +00:00
|
|
|
}
|
2024-03-02 12:41:57 +00:00
|
|
|
|
2024-02-17 12:04:47 +00:00
|
|
|
//
|
2023-11-06 16:38:18 +00:00
|
|
|
if (isset($query['callback'])) {
|
|
|
|
header("Location: ".$query['callback']);
|
|
|
|
} else {
|
2023-11-19 12:24:38 +00:00
|
|
|
header("Location: /profile");
|
2023-11-06 16:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
|
|
|
} else {
|
|
|
|
$message = "Email or password incorrect.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
2024-02-17 12:04:47 +00:00
|
|
|
<div id="loginform">
|
|
|
|
<h2>Sign in to ByeCorps ID</h2>
|
|
|
|
<?php
|
|
|
|
if (isset($message)) {
|
|
|
|
echo "<div class='flash'>$message</div>";
|
|
|
|
}?>
|
|
|
|
<form class="login" method="post">
|
2024-03-02 12:41:57 +00:00
|
|
|
<input type="email" required name="email" id="email" placeholder="Email" />
|
|
|
|
<input type="password" required name="password" id="password" placeholder="Password" />
|
2024-02-17 12:04:47 +00:00
|
|
|
<div class="checkbox"><input type="checkbox" name="keep_logged_in" id="keep_logged_in" />
|
|
|
|
<label for="keep_logged_in">Keep me logged in (for 365 days)</label></div>
|
|
|
|
<button class="primary" type="submit">Sign in</button>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<p class="center">
|
2024-03-02 12:41:57 +00:00
|
|
|
<a href="/forgot/password">Forgot password?</a> • New? <a href="/signup">Sign up</a> for a ByeCorps ID.
|
2024-02-17 12:04:47 +00:00
|
|
|
</p>
|
2024-03-02 12:41:57 +00:00
|
|
|
</div>
|