diff options
| -rw-r--r-- | controllers/login.php | 20 | ||||
| -rw-r--r-- | views/header.php | 1 | ||||
| -rw-r--r-- | views/login/index.php | 26 |
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> |
