From d6806bf3b56135306c62003d4ce23b8b300f5c6e Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Wed, 5 Apr 2023 13:57:28 +0100 Subject: [PATCH] Extend settings.html and .js to include registration --- auth.html | 5 ++--- index.html | 2 +- js/lib.main.js | 10 ++++++++++ js/settings.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ settings.html | 8 ++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/auth.html b/auth.html index ae5d5d1..5bdff3c 100644 --- a/auth.html +++ b/auth.html @@ -30,12 +30,11 @@ OwlBoard Logo -
-

+
diff --git a/index.html b/index.html index 63498c1..6265e1c 100644 --- a/index.html +++ b/index.html @@ -66,7 +66,7 @@
diff --git a/js/lib.main.js b/js/lib.main.js index c1d9e0d..e197167 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -1,3 +1,7 @@ +/* All Page Init */ +const version = "2.0.0-dev"; +versionDisplay(); + /* Feature Detectors */ /* Valid values for ${type}: localstorage, sessionstorage */ @@ -16,6 +20,12 @@ async function storageAvailable(type) { // Currently not used } } +async function versionDisplay() { + localStorage.setItem("version", version) + document.getElementById('ver_str').textContent = version + return; +} + /* Array Converter Converts a string to a single item array */ async function makeArray(data) { diff --git a/js/settings.js b/js/settings.js index e053653..c261d54 100644 --- a/js/settings.js +++ b/js/settings.js @@ -3,6 +3,15 @@ const ql = ["ql0","ql1","ql2","ql3","ql4","ql5","ql6","ql7","ql8","ql9","ql10"," storageAvailable("localStorage"); getQl(); hideLoading(); +ifAlreadyRegistered(); + +async function ifAlreadyRegistered() { + if (! await isRegistered()) { return } else { + document.getElementsByName("eml")[0].placeholder = "Registered"; + document.getElementById("reg_text").textContent = "You are already registered"; + document.getElementById("reg_button").textContent = "Log Out"; + } +} async function getQl(){ var qlOpt = await getQuickLinks() @@ -48,6 +57,47 @@ async function clearQl(){ hideDone(); } +async function isRegistered() { + if (localStorage.getItem("uuid")) { + return true + // Also need an API Call here to check if auth is working. + } + localStorage.removeItem("uuid"); + return false +} + +async function register() { + if (! await isRegistered()) { + showLoading() + let url = `${window.location.origin}/api/v1/auth/request`; + let email = document.getElementById("eml").textContent + let res = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + redirect: "follow", + body: JSON.stringify({email: email}) + }) + if (res.status == 201) { + showDone(); + } + // Need to send a post request to server with the email address + // the server responds with a 201 or a 401 response. + // Then the done popup can appear with a message asking the user + // to check their emails for the link. The link takes then to the + // auth page which has login in auth.js + } else { + logout() + } +} + +async function logout() { + localStorage.removeItem("uuid"); + location.reload(); + return +} + async function showDone() { document.getElementById("done").style = "opacity: 1"; } diff --git a/settings.html b/settings.html index 15cf967..9bba386 100644 --- a/settings.html +++ b/settings.html @@ -67,6 +67,14 @@
+


+
+

Enter your work email address:

+
+

Once you've registered you will receive an email with a link to create your access key.

+

Your email address is not stored by OwlBoard, accounts do not contain any identifying information and are automatically removed after six months of inactivity.

+

You can use the same email address again on another device to register.

+ \ No newline at end of file