Add essential cookies consent gate on auth forms
This commit is contained in:
@@ -40,6 +40,25 @@ function setupHandlers() {
|
||||
}
|
||||
setAuthMode(state.authMode);
|
||||
|
||||
const hasConsent = () => document.cookie.split(";").some((c) => c.trim().startsWith("cookie_consent=1"));
|
||||
const setConsent = () => { document.cookie = "cookie_consent=1; path=/; max-age=31536000; SameSite=Lax"; };
|
||||
const consentRows = document.querySelectorAll(".consent-row");
|
||||
const toggleConsentRows = () => {
|
||||
const hide = hasConsent();
|
||||
consentRows.forEach((row) => row.classList.toggle("hidden", hide));
|
||||
};
|
||||
toggleConsentRows();
|
||||
["login-consent", "register-consent"].forEach((id) => {
|
||||
const box = $(id);
|
||||
if (box) {
|
||||
box.checked = hasConsent();
|
||||
box.addEventListener("change", () => {
|
||||
if (box.checked) setConsent();
|
||||
toggleConsentRows();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const loginUser = $("login-username");
|
||||
if (loginUser) {
|
||||
const markEditing = () => { loginUser.dataset.userEditing = "1"; };
|
||||
@@ -76,8 +95,10 @@ function setupHandlers() {
|
||||
const password = $("login-password").value;
|
||||
if (username.length > 24) return toast("Username must be 24 characters or fewer.", true);
|
||||
if (!username || !password) return toast(t("auth.needCredentials"), true);
|
||||
if (!hasConsent() && !$("login-consent")?.checked) return toast(t("auth.cookieRequired"), true);
|
||||
try {
|
||||
await api.login({ username, password });
|
||||
setConsent();
|
||||
setSavedUsername(username);
|
||||
state.isAuthenticated = true;
|
||||
setAuthUI(true);
|
||||
@@ -102,8 +123,10 @@ function setupHandlers() {
|
||||
if (username.length > 24) return toast("Username must be 24 characters or fewer.", true);
|
||||
if (displayName.length > 16) return toast("Display name must be 16 characters or fewer.", true);
|
||||
if (!username || !password) return toast(t("auth.needCredentials"), true);
|
||||
if (!hasConsent() && !$("register-consent")?.checked) return toast(t("auth.cookieRequired"), true);
|
||||
try {
|
||||
await api.register({ username, password, displayName, adminKey });
|
||||
setConsent();
|
||||
setSavedUsername(username);
|
||||
state.isAuthenticated = true;
|
||||
setAuthUI(true);
|
||||
|
||||
Reference in New Issue
Block a user