From b7bf5a150d00b073bae7a6d3699b5af8198a7695 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 7 Apr 2023 18:59:36 +0100 Subject: [PATCH] Fixes --- index.html | 25 ++++++++++++------------- js/auth.js | 18 +++++++++++++++++- js/settings.js | 9 ++++----- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index 6265e1c..58dd0c6 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,8 @@ - - + + @@ -26,20 +26,20 @@
- - Open menu + + Open menu - - Close menu + + Close menu
@@ -47,7 +47,7 @@ - OwlBoard Logo + OwlBoard Logo
@@ -61,7 +61,6 @@

A fault with our bandwidth provider is causing intermittent connectivity. Apologies for any inconvenience.

-

Customise your quick links on the Settings page.

diff --git a/js/auth.js b/js/auth.js index 096722b..6e5608c 100644 --- a/js/auth.js +++ b/js/auth.js @@ -36,11 +36,27 @@ async function registerKey(key) { // Posts key to server and listens for respons } } +async function checkAuth(key) { + const url = `${window.location.origin}/api/v1/auth/test`; + const res = await fetch(url, { + method: "GET", + redirect: "follow", + headers: { + "uuid": key + } + }) + return res.status === 200 ? true : false +} + async function init(){ // Reads registration key from query, and calls registerKey(key) cmdOut("Reading registration key"); const key = await getQuery("key"); - cmdOut(`Key: ${key}`) + cmdOut(`Temporary: ${key}`) cmdOut("Requesting API Key from server"); let res = await registerKey(key); console.log(JSON.stringify(res)) + cmdOut("Checking key validity") + checkAuth(localStorage.getItem("uuid")) + ? cmdOut("Authentication succesful") + : cmdOut("Authentication failed") } \ No newline at end of file diff --git a/js/settings.js b/js/settings.js index cb23981..4410112 100644 --- a/js/settings.js +++ b/js/settings.js @@ -66,6 +66,7 @@ async function isRegistered() { // Check if a device is registered, returns BOOL if (localStorage.getItem("uuid")) { return true // Also need an API Call here to check if auth is working. + // A Suitable function exists in auth.js - move it to lib.main.js } localStorage.removeItem("uuid"); return false @@ -86,12 +87,10 @@ async function register() { // Registers a device by sending POST request to API }) if (res.status == 201) { showDone(); + hideLoading(); + return; } - // 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 + log(`settings.register: Error: Fetch returned: ${res.status}`, "err") } else { logout() }