fixed token setting

This commit is contained in:
Leonard Lorenz 2020-11-02 16:04:22 +01:00
parent 5109d75e1a
commit 4fe6704e72

View file

@ -2,7 +2,7 @@ function setTokenCookie() {
let token = document.getElementById('set-token').value;
let tokenCookie = 'token=' + token + "; SameSite=None; secure";
document.cookie = tokenCookie;
document.getElementById("token").value = token
setFormTokens(token);
document.getElementById("cookie-block").hidden = true;
}
@ -11,6 +11,13 @@ function clearTokenCookie() {
document.getElementById("cookie-block").hidden = false;
}
function setFormTokens(token) {
let tokenFields = document.querySelectorAll(".token");
for (t of tokenFields) {
t.value = token;
}
}
// if cookie is set, use it to pass the token
let c_pairs = document.cookie.split(";");
let cookie_set = false;
@ -18,10 +25,7 @@ for (c of c_pairs) {
if (c.trim().split("=")[0].startsWith("token")){
// stick token into all the form input fields
let token = c.split("=")[1];
let tokenFields = document.querySelectorAll(".token");
for (t of tokenFields) {
t.value = token;
}
setFormTokens(token);
cookie_set = true;
}
}