aboutsummaryrefslogtreecommitdiff
path: root/views/user
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2025-02-02 12:23:02 +0200
committerSyndamia <kamen@syndamia.com>2025-02-02 12:23:02 +0200
commit0d5738a2bc9dd4f5edf582f7cea3614bcbb44842 (patch)
tree1ddb7845d85ff5126e33c3e72cbcc18c2f31b511 /views/user
parent14c84a83bcad285219539821647ee2d988eabaa8 (diff)
downloadnowayforward_human-0d5738a2bc9dd4f5edf582f7cea3614bcbb44842.tar
nowayforward_human-0d5738a2bc9dd4f5edf582f7cea3614bcbb44842.tar.gz
nowayforward_human-0d5738a2bc9dd4f5edf582f7cea3614bcbb44842.zip
feat!(views): Rename profile to user
Diffstat (limited to 'views/user')
-rw-r--r--views/user/authenticate.php24
-rw-r--r--views/user/index.php73
-rw-r--r--views/user/meta.php4
3 files changed, 101 insertions, 0 deletions
diff --git a/views/user/authenticate.php b/views/user/authenticate.php
new file mode 100644
index 0000000..e4cf47e
--- /dev/null
+++ b/views/user/authenticate.php
@@ -0,0 +1,24 @@
+<?php
+
+if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
+ header('Allow: POST');
+ http_response_code(405);
+ header('Content-Type: text/plain');
+ echo $_SERVER['REQUEST_METHOD'] . " request not allowed!";
+ exit;
+}
+
+try {
+ $user = Database\Cookie::fromDB($TOKEN);
+
+ http_response_code(200);
+ header('Content-Type: text/plain');
+ echo $user->Username;
+}
+catch(Exception $e) {
+ http_response_code(401);
+ header('Content-Type: text/plain');
+ echo 'Bad token!';
+}
+
+exit;
diff --git a/views/user/index.php b/views/user/index.php
new file mode 100644
index 0000000..1462e26
--- /dev/null
+++ b/views/user/index.php
@@ -0,0 +1,73 @@
+<?php
+ $user = null;
+ try {
+ $user = Database\User::fromDB($username);
+ }
+ catch(Exception $e) {}
+?>
+
+<?php if ($user !== null): ?>
+ <section>
+ <span class="user-icon"><?php $user->icon(); ?></span>
+ <h1 class="username"><?= $user->Username ?></h1>
+ </section>
+
+ <div class="user-blank-afterspace"></div>
+
+ <section id="user-buttons" hidden>
+ <form action="/list/new" method="GET">
+ <input type="submit" value="Create a new list">
+ </form>
+ </section>
+ <script type="text/javascript">
+ function showUserButtons() {
+ document.getElementById('user-buttons').hidden = false;
+ }
+ authenticated(showUserButtons);
+ </script>
+
+ <nav id="user-nav">
+ <button id="openArchives" onclick="openArchives()">Archives</button>
+ <button id="openLists" onclick="openLists()" class="not-selected">Lists</button>
+ </nav>
+ <section id="userArchives">
+ <?php
+ foreach ($user->archives() as $page) {
+ include $VIEWS_DIR . '/archive/item.php';
+ }
+ include_once $VIEWS_DIR . '/archive/item_show.php';
+ ?>
+ </section>
+
+ <section id="userLists" hidden>
+ <?php
+ foreach ($user->archiveLists() as $list) {
+ include $VIEWS_DIR . '/list/item.php';
+ }
+ include_once $VIEWS_DIR . '/list/item_show.php';
+ ?>
+ </section>
+
+ <script type="text/javascript">
+ const elemOpenArchives = document.getElementById('openArchives');
+ const elemOpenLists = document.getElementById('openLists');
+ const userArchives = document.getElementById('userArchives');
+ const userLists = document.getElementById('userLists');
+
+ function openArchives() {
+ elemOpenArchives.classList.remove('not-selected');
+ elemOpenLists.classList.add('not-selected');
+ userArchives.hidden = false;
+ userLists.hidden = true;
+ }
+ function openLists() {
+ elemOpenArchives.classList.add('not-selected');
+ elemOpenLists.classList.remove('not-selected');
+ userArchives.hidden = true;
+ userLists.hidden = false;
+ }
+ </script>
+
+<?php else: ?>
+ <h2>User "<?= $username ?>" doesn't exist!</h2>
+<?php endif; ?>
diff --git a/views/user/meta.php b/views/user/meta.php
new file mode 100644
index 0000000..52764ef
--- /dev/null
+++ b/views/user/meta.php
@@ -0,0 +1,4 @@
+<?php
+
+$username = explode('/', $uri, 4)[2];
+$title = "$username's profile";