summaryrefslogtreecommitdiffstats
path: root/index.php
blob: 0a1d9b201b5bb6fd1a4983367e92ae6f2e5e948e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
session_start();
if ($_SESSION["logged"] === true) {
  header("HTTP/1.0 307 Teapot is waiting for you :>");
  header("Location: main.php");
}
?>
<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">

  <title>CMS - Login</title>
</head>

<body class="bg-dark text-white">
  <form method="POST" action="login.php" class="container" style="margin: 0 auto; width: fit-content">
    <h1 class="text-center fw-bold">Login</h1>
    <div>
      <label for="username" class="m-1">Username:</label><br>
      <input type="text" name="username" id="username" size="30"><br>
    </div>
    <div style="margin-top: 30px;">
      <label for="password" class="m-1">Password:</label><br>
      <input type="password" name="password" id="password" size="30">
    </div>
    <div style="margin-top: 15px;">
      <div style="float: left;">
        <input type="checkbox" name="remember" id="remember">
        <label for="remember">Remember me</label>
      </div>
      <div style="float: right;">
        <a href="#">Forgot password?</a>
      </div>
    </div>
    <div class="text-center" style="margin-top: 70px;">
      <button type="submit" class="btn btn-primary btn-lg">Log in</button>
    </div>
    <div style="margin-top: 30px;">
      <div style="float: right;">
        <a href="#">You don't have an account?</a>
      </div>
    </div>
  </form>
  <div class="modal fade" id="errorModal" tabindex="-1" aria-labelledby="errorModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title text-dark" id="errorModalLabel">Error</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body text-dark">
          <?= $_SESSION["error"] ?>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
  <button type="button" style="display: none;" id="btnErrorModal" data-bs-toggle="modal" data-bs-target="#errorModal">
  </button>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>
  <script>
    let errorModal = new bootstrap.Modal(document.getElementById('errorModal'));
    let show = <?= isset($_SESSION["error"]) === true ? 1 : 0 ?>;
    if (show === 1)
      errorModal.show();

    function getCookie(name) {
      const parts = `; ${document.cookie}`.split(`; ${name}=`);
      if (parts.length === 2) return parts.pop().split(';').shift();
      else return null;
    }
    let username = getCookie("username");
    console.log(username)
    if(username !== null) {
      document.getElementById("username").value = getCookie("username");
      document.getElementById("remember").checked = true;
    }
  </script>
</body>
<?php unset($_SESSION["error"]); ?>

</html>