From da7adea36e42b3b09eb25c47a8e4ce4a6e7505d9 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 1 Jan 2024 09:19:04 +0000 Subject: [PATCH] feat: Moved the JS out of the register page into its own file Related to #9 --- src/register.html | 97 ---------------------------------------- src/register/index.html | 56 +++++++++++++++++++++++ src/register/register.js | 56 +++++++++++++++++++++++ 3 files changed, 112 insertions(+), 97 deletions(-) delete mode 100644 src/register.html create mode 100644 src/register/index.html create mode 100644 src/register/register.js diff --git a/src/register.html b/src/register.html deleted file mode 100644 index e915177..0000000 --- a/src/register.html +++ /dev/null @@ -1,97 +0,0 @@ - - - - - Skynet Register - - - - -
- -
-

Register

-

- Thank you for signing up for your Skynet account. -
- Please complete the process by filling in the form below. -
- Username is what you want to be known on Skynet as. -
- It must be lowercase, start with a letter and contain only 0-9 a-z and _- -

-
- - - - - - - - - - - - - - - - -


-
-

- -
-
- UL Computer Society 2023-2023 - -
-
- - \ No newline at end of file diff --git a/src/register/index.html b/src/register/index.html new file mode 100644 index 0000000..9cfd259 --- /dev/null +++ b/src/register/index.html @@ -0,0 +1,56 @@ + + + + + Skynet Register + + + + +
+ +
+

Register

+

+ Thank you for signing up for your Skynet account. +
+ Please complete the process by filling in the form below. +
+ Username is what you want to be known on Skynet as. +
+ It must be lowercase, start with a letter and contain only 0-9 a-z and _- +

+
+ + + + + + + + + + + + + + + + +


+
+

+ +
+
+ UL Computer Society 2023-2023 + +
+
+ + \ No newline at end of file diff --git a/src/register/register.js b/src/register/register.js new file mode 100644 index 0000000..2e5f9a8 --- /dev/null +++ b/src/register/register.js @@ -0,0 +1,56 @@ +const form = document.getElementById("form"); +form.addEventListener('submit', formHandler); + +const form_status = document.getElementById("formStatus"); + +const button = document.getElementById("button"); +button.addEventListener('submit', formHandler); + +async function formHandler(listener) { + listener.preventDefault(); + const formData = new FormData(form); + const pass = formData.get("pass"); + + if (pass !== formData.get("confirm")) { + form_status.innerHTML = `Passwords don't match`; + return; + } + + + const urlParam = new URLSearchParams(new URL(window.location.href).search); + const auth = urlParam.get("auth"); + + // if there is no auth value then return here + if(!auth){ + return; + } + + const user = formData.get("user"); + const body = {auth: auth, user: user, pass: pass}; + + let url = 'https://api.account.skynet.ie/ldap/new/account'; + let req; + + try { + req = await fetch(url, { + method: 'POST', + body: JSON.stringify(body), + mode: "cors" + }); + } catch (e) { + form_status.innerHTML = `${e}`; + return; + } + + if (req.status !== 200) { + form_status.innerHTML = "Failure"; + return; + } + + let temp = await req.json(); + if (temp.result === 'error') { + form_status.innerHTML = `${temp.error}`; + } else { + form_status.innerHTML = "Success"; + } +} \ No newline at end of file