bozza di checkLogin

This commit is contained in:
boyska 2022-03-22 21:46:44 +01:00
parent fff408bd24
commit d0b372bcef

View file

@ -1,3 +1,13 @@
async function checkLogin() {
let resp = await fetch('../whoami', {
method: 'POST',
})
console.log('ok', resp)
data = await resp.json()
console.log('got', data)
// try... catch?
}
async function onGenerate(evt) {
let resp = await fetch('../generate', {
method: 'POST',
@ -8,6 +18,7 @@ async function onGenerate(evt) {
document.getElementById("generate-label").value = data.password
document.getElementById("accept-btn").removeAttribute('disabled')
}
async function onAccept(evt) {
document.getElementById("generate-btn").setAttribute('disabled', 'disabled')
let resp = await fetch('../change', {
@ -25,11 +36,14 @@ async function onAccept(evt) {
document.getElementById("accept-btn").setAttribute('disabled', 'disabled')
}
}
function initChange() {
checkLogin()
document.getElementById("generate-label").value = ""
document.getElementById("accept-btn").setAttribute('disabled', 'disabled')
document.getElementById("generate-btn").addEventListener('click', onGenerate, false)
document.getElementById("accept-btn").addEventListener('click', onAccept, false)
}
document.addEventListener('DOMContentLoaded', initChange)