38 lines
888 B
JavaScript
38 lines
888 B
JavaScript
|
const cmd = document.getElementById("cmd")
|
||
|
init();
|
||
|
|
||
|
async function sendHome(){
|
||
|
await delay(2000);
|
||
|
location.replace('/')
|
||
|
}
|
||
|
|
||
|
async function cmdOut(message) {
|
||
|
html = "<p>" + message + "</p>"
|
||
|
cmd.insertAdjacentHTML("beforeend", html)
|
||
|
}
|
||
|
|
||
|
async function registerKey(key) {
|
||
|
var url = `${window.location.origin}/api/v1/auth/register`;
|
||
|
let res = await fetch(url, {
|
||
|
method: "POST",
|
||
|
headers: {
|
||
|
"Content-Type": "application/json"
|
||
|
},
|
||
|
redirect: "follow",
|
||
|
body: JSON.stringify(key)
|
||
|
})
|
||
|
if (res.JSON['result'] == "ok"){
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function init(){
|
||
|
cmdOut("Reading registration key");
|
||
|
const key = await getQuery("key");
|
||
|
cmdOut(`Key: ${key}`)
|
||
|
cmdOut("Requesting API Key from server");
|
||
|
let res = await registerKey(key);
|
||
|
console.log(JSON.stringify(res))
|
||
|
}
|