<?php
session_start();
%PLEAZE_NO_CACHE%
  $navbar = "login";
if (isset($_SESSION['user_id'])){
  if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
  }
  session_destroy();
}
?>
<!DOCTYPE html>
<html>
  <head>
    <title>ThreadR - Log In</title>
    %STYLESHEET%
    <link rel="icon" type="image/png" href="%CONTENT_DIR%/img/favicon-32x32.png" sizes="32x32" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>
  <body>
    %NAVBAR%
    <br />
    <div class="container">
      <div class="item-1">
        <h1> <center>Log in to your ThreadR account</center> </h1>
      </div>
      <div class="item-2">
        <section>
          <p>
            <?php
            if (isset($_GET['error'])){
              if ($_GET['error'] == "credentials"){
                echo "Invalid credentials. Try again:";
              }
              if ($_GET['error'] == "session"){
                echo "You are not logged in or your session has been closed. We are sorry for the inconvenience.";
              }
            } else {
              echo "Login:";
            }
            ?></p>
          <form action="%CONTENT_DIR%/login/redirect.php" method="post">
            <input type="text" name="username" maxlength="20" placeholder="Username" />
            <input type="password" name="password" maxlength="256" placeholder="Password" />
            <p></p>
            <input type="submit" value="Log in" />
          </form>
          <p></p>
        </section>
      </div>
      <div class="item-3 margin">
        <p></p>
        <a href="%CONTENT_DIR%/signup/"> <button> Register </button> </a>
        <p></p>
      </div>
      <!-- <div class="item-4">
        <center><a href="https://lostcave.ddnss.de%CONTENT_DIR%/about/">About</a></center>
      </div> -->
    </div>
    %BANNER_COOKIES%
  </body>
</html>
