aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2025-01-25 19:59:22 +0200
committerSyndamia <kamen@syndamia.com>2025-01-25 19:59:25 +0200
commitf6dbaf91e950657f97c456a296e5a76e27d4cb10 (patch)
tree6c3ad506f355f06f3612b1dd2913d75b27d618ba
parentbd2b3acd9c4f54fc13d341b977371393be50fbd6 (diff)
downloadnowayforward_human-f6dbaf91e950657f97c456a296e5a76e27d4cb10.tar
nowayforward_human-f6dbaf91e950657f97c456a296e5a76e27d4cb10.tar.gz
nowayforward_human-f6dbaf91e950657f97c456a296e5a76e27d4cb10.zip
feat(views/login): Add login page
-rw-r--r--controllers/login.php20
-rw-r--r--views/header.php1
-rw-r--r--views/login/index.php26
3 files changed, 47 insertions, 0 deletions
diff --git a/controllers/login.php b/controllers/login.php
new file mode 100644
index 0000000..75c62ac
--- /dev/null
+++ b/controllers/login.php
@@ -0,0 +1,20 @@
+<?php
+
+function on_post() {
+ global $status;
+ global $token;
+ $status = "";
+
+ try {
+ $user = Database\User::fromDB($_POST["username"]);
+ if (password_verify($_POST["password"], $user->Password)) {
+ $token = Database\Cookie::create($user->UID);
+ }
+ else {
+ $status = "Incorrect password!";
+ }
+ }
+ catch(Exception $e) {
+ $status = "User \"" . $_POST["username"] . "\" doesn't exist!";
+ }
+}
diff --git a/views/header.php b/views/header.php
index ace2eb7..30e9638 100644
--- a/views/header.php
+++ b/views/header.php
@@ -16,6 +16,7 @@
<a href="/test/index.php">Test</a>
<a href="/sample_archive/index.php">Sample Archive</a>
<div class="flex-expand"></div>
+ <a href="/login/index.php">Login</a>
<a href="/register/index.php">Register</a>
<div class="fadeout-right"></div>
</nav>
diff --git a/views/login/index.php b/views/login/index.php
new file mode 100644
index 0000000..a77f106
--- /dev/null
+++ b/views/login/index.php
@@ -0,0 +1,26 @@
+<?php
+ $title = 'Login to your account';
+ include '../meta.php';
+
+ $status = null;
+ $token = null;
+ runController('login');
+?>
+
+<?php if ($status !== null): ?>
+ <?php if ($status !== ""): ?>
+ <p>
+ Fail: <?php echo $status ?>
+ </p>
+ <?php else: ?>
+ <p>
+ Success! Token: <?php echo $token ?>
+ </p>
+ <?php endif; ?>
+<?php endif; ?>
+
+<form action="./index.php" method="POST">
+ <input type="text" name="username" placeholder="Username" minlength="1" pattern="[A-Za-z][A-Za-z_0-9]*">
+ <input type="password" name="password" placeholder="Password" minlength="4">
+ <input type="submit" value="Login">
+</form>