<?php
session_start();
if (isset($_SESSION['user']['user_uuid'])) {
    header('Location: /');
    exit;
}

require_once "{$_SERVER['DOCUMENT_ROOT']}/login/php/authFunctions.php";
$loginAttempts = checkLoginAttempts();

?>

<!DOCTYPE html>
<html data-coreui-theme="dark" lang="en">
<head>
    <base href="./">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta name="description" content="Sentri - Configure phone configs">
    <meta name="author" content="Marco Mooij">
    <meta name="keyword" content="sentri">
    <title>Sentri | Login</title>

    <!-- favicon -->
    <link rel="icon" type="image/png" href="/src/images/favicon/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/svg+xml" href="/src/images/favicon/favicon-96x96.png">
    <link rel="shortcut icon" href="/src/images/favicon/favicon.ico">
    <link rel="apple-touch-icon" sizes="180x180" href="/src/images/favicon/apple-touch-icon.png">
    <link rel="manifest" href="/src/images/favicon/site.webmanifest">

    <link rel="stylesheet" href="css/style.full.css" as="style">
</head>
<body>
<div class="bg-body-tertiary min-vh-100 d-flex flex-row align-items-center">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-8 col-md-10 col-12 d-flex align-items-center justify-content-center">
                <div class="card-group d-block d-md-flex row">
                    <div class="card col-md-7 mb-0 border-0">
                        <div class="card-body p-3">
                            <div class="card-body justify-content-center align-items-center">
                                <?php if (isset($_GET['result'])) {
                                    if ($_GET['result'] == "success") { ?>
                                        <h1 class="">Request sent!</h1>
                                        <p class="">If an account with that email address exists, we’ve sent a password reset link to your inbox. Please check your email.</p>
                                        <hr>
                                        <a href="/login/" class="btn btn-primary px-4">
                                            <i class="fa-solid fa-check"></i> Go to login
                                        </a>
                                    <?php } elseif ($_GET['result'] == "failed") { ?>
                                        <h1 class="text-center">Something went wrong :(</h1>
                                        <p class="text-center">Something went wrong in requesting your forgotten password. Please contact support!</p>
                                    <?php } elseif ($_GET['result'] == "blocked") { ?>
                                        <h1 class="text-center">Blocked</h1>
                                        <p class="text-center">You’ve been temporarily blocked after multiple failed login attempts. Please try again later or contact support.</p>
                                    <?php } ?><?php } else { ?>
                                    <h1>Forgot password</h1>
                                    <p>Enter your email and we’ll send you a reset link.</p>

                                    <form method="post" action="/login/php/forgotPasswordRequest.php">
                                        <div class="mb-3 text-reset">
                                            <label for="email"></label>
                                            <input type="email" class="form-control" name="user_email" id="email" placeholder="somebody@somewhere.what" required>
                                        </div>

                                        <button type="submit" class="btn btn-primary w-100" id="submitBtn">
                                            <i class="fa-solid fa-envelope"></i> Request email
                                        </button>
                                    </form>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                    <div class="card col-md-5 text-white bg-transparent py-0 border-0">
                        <div class="card-body text-center pt-5">
                            <div>
                                <img class="pt-3 w-100 portal-image" alt="portal-image" src="" width="500" height="265">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</body>
</html>
