feat: check for password existence

This commit is contained in:
insects 2025-03-11 01:12:30 +01:00
parent b03df8f0e4
commit 498ecdf68b
7 changed files with 73 additions and 15 deletions

22
app/javascript/list.js Normal file
View file

@ -0,0 +1,22 @@
function checkPwd() {
const ls = window.localStorage;
const id = document.getElementById("public_id").dataset.content;
const pwd = ls.getItem(`ecoffee-pwd:${id}`);
if (pwd) {
const to_show = document.querySelectorAll(".needs_pwd");
to_show.forEach(el => {
el.classList.add("shown");
});
const buttons = document.querySelectorAll(".action button");
buttons.forEach(btn => {
const oldUrl= btn.getAttribute("hx-post");
btn.setAttribute("hx-post", `${oldUrl}&pwd=${pwd}`);
});
}
}
checkPwd();
document.addEventListener("htmx:afterRequest", evt => {
checkPwd();
})

View file

@ -0,0 +1,12 @@
const id = document.getElementById("public_id");
const pwd = document.getElementById("password");
const ls = window.localStorage;
if (id && pwd) {
ls.setItem(`ecoffee-pwd:${id.dataset.content}`, pwd.dataset.content);
}
let loc = new URL(window.location.href);
loc.search = "";
loc.pathname = `/${id.dataset.content}`;
window.location = loc;