summaryrefslogtreecommitdiff
path: root/signin
diff options
context:
space:
mode:
Diffstat (limited to 'signin')
-rwxr-xr-xsignin/content.html20
-rwxr-xr-xsignin/signin.php57
2 files changed, 76 insertions, 1 deletions
diff --git a/signin/content.html b/signin/content.html
index 458ecfb..ac9eb13 100755
--- a/signin/content.html
+++ b/signin/content.html
@@ -16,4 +16,22 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
-<p>WIP</p>
+<h2>Sign in to GNUfault.org</h2>
+<hr>
+<p>If you need any help, email me at &lt;<a href="mailto:noreply@gnufault.org">connor@gnufault.org</a>&gt;.</p>
+<br>
+<form class="login" action="signin.php" method="POST">
+ <div class="group">
+ <label for="username">Username:</label>
+ <input class="input" type="text" id="username" name="username" required>
+ </div>
+ <div class="group">
+ <label for="password">Password:</label>
+ <input class="input" type="password" id="password" name="password" required>
+ </div>
+ <div class="group">
+ <label for="remember">Remember me:</label>
+ <input class="checkbox" type="checkbox" id="remember" name="remember" checked>
+ </div>
+ <button class="button" type="submit">Send</button>
+</form>
diff --git a/signin/signin.php b/signin/signin.php
new file mode 100755
index 0000000..6e88336
--- /dev/null
+++ b/signin/signin.php
@@ -0,0 +1,57 @@
+<?php
+/*
+ * GNUfault.org - GNUfault's website
+ * Copyright (C) 2026 Connor Thomson
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+define('ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/');
+
+require_once ROOT . '/php/session.php';
+require_once ROOT . '/php/database.php';
+
+if ($_SERVER["REQUEST_METHOD"] == "POST") {
+ $username = $_POST['username'];
+ $password = $_POST['password'];
+ $remember = isset($_POST['remember']);
+
+ try {
+ $sql = "SELECT id, username, password, verification_code FROM users WHERE username = :username";
+
+ $user = fetch_row($sql, ['username' => $username]);
+ } catch (\PDOException $e) {
+ echo "Error: " . $e->getMessage();
+ exit;
+ }
+
+ // The same message either way, so it does not say which usernames exist
+ if (!$user || !password_verify($password, $user['password'])) {
+ echo "Username or password is not correct!";
+ exit;
+ }
+
+ if ($user['verification_code'] != '0001') {
+ set_user_id((int)$user['id']);
+
+ header("Location: /signup/verify");
+ exit;
+ }
+
+ sign_in((int)$user['id'], $user['username'], $remember);
+
+ header("Location: /");
+}
+
+?>