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 _- -

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


-
-

- -
- -
- - \ 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 _- +

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


+
+

+ +
+ +
+ + \ 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