diff options
| author | Syndamia <kamen@syndamia.com> | 2025-01-25 19:31:14 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-01-25 19:59:25 +0200 |
| commit | f7db20f6a635a4195647941a8c150a1bb3fcf904 (patch) | |
| tree | d2498a078139fc1caebcf83ae5d05d9acaf88550 | |
| parent | 046dc2e32512dad2458be3e367e16e6e1a6f46f3 (diff) | |
| download | nowayforward_human-f7db20f6a635a4195647941a8c150a1bb3fcf904.tar nowayforward_human-f7db20f6a635a4195647941a8c150a1bb3fcf904.tar.gz nowayforward_human-f7db20f6a635a4195647941a8c150a1bb3fcf904.zip | |
feat(views): Add basic profile and register views
| -rw-r--r-- | controllers/register.php | 19 | ||||
| -rw-r--r-- | controllers/user.php | 9 | ||||
| -rw-r--r-- | views/header.php | 1 | ||||
| -rw-r--r-- | views/profile/index.php | 16 | ||||
| -rw-r--r-- | views/register/index.php | 25 |
5 files changed, 70 insertions, 0 deletions
diff --git a/controllers/register.php b/controllers/register.php new file mode 100644 index 0000000..3e8d416 --- /dev/null +++ b/controllers/register.php @@ -0,0 +1,19 @@ +<?php + +function on_post() { + global $status; + $status = ""; + try { + Database\User::fromDB($_POST["username"]); + $status = "User \"" . $_POST["username"] . "\" already exists!"; + return; + } + catch(Exception $e) {} + + try { + Database\User::create($_POST["username"], $_POST["password"], "User"); + } + catch(Exception $e) { + $status = $e; + } +} diff --git a/controllers/user.php b/controllers/user.php new file mode 100644 index 0000000..f26103e --- /dev/null +++ b/controllers/user.php @@ -0,0 +1,9 @@ +<?php + +function on_get() { + global $user; + try { + $user = Database\User::fromDB($_GET["user"]); + } + catch(Exception $e) {} +} diff --git a/views/header.php b/views/header.php index 40afb0b..ace2eb7 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="/register/index.php">Register</a> <div class="fadeout-right"></div> </nav> </header> diff --git a/views/profile/index.php b/views/profile/index.php new file mode 100644 index 0000000..3e79d71 --- /dev/null +++ b/views/profile/index.php @@ -0,0 +1,16 @@ +<?php + $title = $_GET["user"] . ' - Profile'; + include '../meta.php'; + + $user = null; + runController('user'); +?> + +<?php if ($user !== null): ?> + <section> + <?php echo $user->Username ?> + <?php echo $user->Role ?> + </section> +<?php else: ?> + <h2>User "<?php echo $_GET["user"] ?>" doesn't exist!</h2> +<?php endif; ?> diff --git a/views/register/index.php b/views/register/index.php new file mode 100644 index 0000000..4e2abb1 --- /dev/null +++ b/views/register/index.php @@ -0,0 +1,25 @@ +<?php + $title = 'Register a new user'; + include '../meta.php'; + + $status = null; + runController('register'); +?> + +<?php if ($status !== null): ?> + <?php if ($status !== ""): ?> + <p> + Fail: <?php echo $status ?> + </p> + <?php else: ?> + <p> + Success! + </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="Register"> +</form> |
