pis #2

Merged
fred.boniface merged 76 commits from pis into main 2023-05-06 21:53:45 +01:00
3 changed files with 14 additions and 15 deletions
Showing only changes of commit 7fbe592529 - Show all commits

View File

@ -19,21 +19,19 @@ async function cmdOut(message) {
}
async function registerKey(key) { // Posts key to server and listens for response.
var url = `${window.location.origin}/api/v1/register/register`;
let res = await fetch(url, { // The response will contain the UUID which will be registered
const url = `${window.location.origin}/api/v1/register/register`;
const res = await fetch(url, { // The response will contain the UUID which will be registered
method: "POST",
headers: {
"Content-Type": "application/json"
},
redirect: "follow",
body: JSON.stringify(key)
body: JSON.stringify({uuid: key})
})
if (res.JSON['result'] == "ok"){
localStorage.setItem("uuid", res.JSON['uuid']);
return true;
} else {
return false;
}
const data = await res.json();
return res.status === 201
? (localStorage.setItem("uuid", data.uuid), true)
: false;
}
async function checkAuth(key) {
@ -53,10 +51,12 @@ async function init(){ // Reads registration key from query, and calls registerK
const key = await getQuery("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"))
if (!await registerKey(key)) {
cmdOut("Failed to register key")
hideLoading()
return
}
await checkAuth(localStorage.getItem("uuid"))
? cmdOut("Authentication succesful")
: cmdOut("Authentication failed")
}

View File

@ -9,7 +9,6 @@ if ("serviceWorker" in navigator) {
async function pageInit() {
await loadQuickLinks();
hideLoading(); // From lib.main
localStorage.setItem("ver-web", document.getElementById('ver_str').textContent)
}
async function gotoBoard(station){

View File

@ -78,7 +78,7 @@ async function register() { // Registers a device by sending POST request to API
if (! await isRegistered()) {
showLoading()
let url = `${window.location.origin}/api/v1/register/request`;
let email = document.getElementById("eml").textContent
let email = document.getElementById("eml").value
let res = await fetch(url, {
method: "POST",
headers: {