diff --git a/static/js/change.js b/static/js/change.js index e67839f..ee1fd8e 100644 --- a/static/js/change.js +++ b/static/js/change.js @@ -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)