This commit is contained in:
Fred Boniface 2023-04-07 18:59:36 +01:00
parent 38a0cc55e2
commit b7bf5a150d
3 changed files with 33 additions and 19 deletions

View File

@ -7,8 +7,8 @@
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">
<meta name="theme-color" content="#00b7b7"> <meta name="theme-color" content="#00b7b7">
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png"> <link rel="apple-touch-icon" href="./images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/main.css"/> <link rel="stylesheet" href="./styles/main.css"/>
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/> <link rel="icon" type="image/svg+xml" href="./images/icon.svg"/>
<link rel="manifest" type="application/json" href="./manifest.json"/> <link rel="manifest" type="application/json" href="./manifest.json"/>
<script src="./js/lib.main.js" defer></script> <script src="./js/lib.main.js" defer></script>
@ -26,20 +26,20 @@
<!-- Popup Menu --> <!-- Popup Menu -->
<div id="top_button" class="hide_micro"> <div id="top_button" class="hide_micro">
<picture aria-label="Menu" class="sidebar_control" id="sidebar_open_short" onclick="sidebarOpen()"> <picture aria-label="Menu" class="sidebar_control" id="sidebar_open_short" onclick="sidebarOpen()">
<source srcset="/images/nav/hamburger.svg" type="image/svg+xml"> <source srcset="./images/nav/hamburger.svg" type="image/svg+xml">
<img src="hamburger_40.png" alt="Open menu"> <img src="./images/nav/hamburger_40.png" alt="Open menu">
</picture> </picture>
<picture aria-label="Close Menu" class="sidebar_control" id="sidebar_close_short" onclick="sidebarClose()"> <picture aria-label="Close Menu" class="sidebar_control" id="sidebar_close_short" onclick="sidebarClose()">
<source srcset="/images/nav/close.svg" type="image/svg+xml"> <source srcset="./images/nav/close.svg" type="image/svg+xml">
<img src="close-40.png" alt="Close menu"> <img src="./images/nav/close-40.png" alt="Close menu">
</picture> </picture>
</div> </div>
<div id="sidebar"> <div id="sidebar">
<a href="/">Home</a> <a href="./">Home</a>
<a href="/find-code.html">Code Search</a> <a href="./find-code.html">Code Search</a>
<a href="/settings.html">Settings</a> <a href="./settings.html">Settings</a>
<a href="/help.html">Help</a> <a href="./help.html">Help</a>
<a href="/issue.html">Report Issue</a> <a href="./issue.html">Report Issue</a>
</div> </div>
<!-- Main Content Begins --> <!-- Main Content Begins -->
@ -47,7 +47,7 @@
<source srcset="/images/logo/wide_logo.svg" type="image/svg+xml"> <source srcset="/images/logo/wide_logo.svg" type="image/svg+xml">
<source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png"> <source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png">
<source srcset="/images/logo/logo-full-250.png" type="image/png"> <source srcset="/images/logo/logo-full-250.png" type="image/png">
<img class="titleimg" src="/images/logo/logo-full-250.png" alt="OwlBoard Logo"> <img class="titleimg" src="./images/logo/logo-full-250.png" alt="OwlBoard Logo">
</picture> </picture>
<br> <br>
<form action="board.html"> <form action="board.html">
@ -61,7 +61,6 @@
</div> </div>
<div class="text-description"> <div class="text-description">
<p>A fault with our bandwidth provider is causing intermittent connectivity. Apologies for any inconvenience.</p> <p>A fault with our bandwidth provider is causing intermittent connectivity. Apologies for any inconvenience.</p>
</p>
<p>Customise your quick links on the <a href="/settings.html">Settings</a> page.</p> <p>Customise your quick links on the <a href="/settings.html">Settings</a> page.</p>
</div> </div>
<!-- Footer --> <!-- Footer -->

View File

@ -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) async function init(){ // Reads registration key from query, and calls registerKey(key)
cmdOut("Reading registration key"); cmdOut("Reading registration key");
const key = await getQuery("key"); const key = await getQuery("key");
cmdOut(`Key: ${key}`) cmdOut(`Temporary: ${key}`)
cmdOut("Requesting API Key from server"); cmdOut("Requesting API Key from server");
let res = await registerKey(key); let res = await registerKey(key);
console.log(JSON.stringify(res)) console.log(JSON.stringify(res))
cmdOut("Checking key validity")
checkAuth(localStorage.getItem("uuid"))
? cmdOut("Authentication succesful")
: cmdOut("Authentication failed")
} }

View File

@ -66,6 +66,7 @@ async function isRegistered() { // Check if a device is registered, returns BOOL
if (localStorage.getItem("uuid")) { if (localStorage.getItem("uuid")) {
return true return true
// Also need an API Call here to check if auth is working. // 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"); localStorage.removeItem("uuid");
return false return false
@ -86,12 +87,10 @@ async function register() { // Registers a device by sending POST request to API
}) })
if (res.status == 201) { if (res.status == 201) {
showDone(); showDone();
hideLoading();
return;
} }
// Need to send a post request to server with the email address log(`settings.register: Error: Fetch returned: ${res.status}`, "err")
// 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 { } else {
logout() logout()
} }