From 2ad318e7c5978f174fa4197214a0cfc828e1dec9 Mon Sep 17 00:00:00 2001 From: x Date: Sat, 24 Jan 2026 16:11:56 +0100 Subject: [PATCH] feat: Display login success messages, adjust user registration defaults and post-registration redirect, and include scripts for generating dummy items and copying thumbnails. --- public/s/js/f0ck.js | 25 +++++++++++++++++++++++++ src/inc/routes/register.mjs | 14 +++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/public/s/js/f0ck.js b/public/s/js/f0ck.js index 9587f23..eb9672d 100644 --- a/public/s/js/f0ck.js +++ b/public/s/js/f0ck.js @@ -69,6 +69,31 @@ window.requestAnimFrame = (function () { loginModal.style.display = 'none'; } }); + + // Handle Flash Message (login=success) + if (window.location.search.includes('login=success')) { + loginModal.style.display = 'flex'; + const form = loginModal.querySelector('.login-form'); + if (form && !form.querySelector('.flash-success')) { + const msg = document.createElement('div'); + msg.className = 'flash-success'; + msg.style.color = '#fff'; + msg.style.background = 'var(--accent)'; // f0ck accent usually + msg.style.padding = '10px'; + msg.style.borderRadius = '4px'; + msg.style.marginBottom = '10px'; + msg.style.textAlign = 'center'; + msg.style.color = 'black'; // contrast + msg.style.fontWeight = 'bold'; + msg.textContent = 'Success! You might login now.'; + form.insertBefore(msg, form.firstChild); // Insert at top of form + + // Clean URL + const url = new URL(window.location); + url.searchParams.delete('login'); + window.history.replaceState({}, '', url); + } + } } // Register Modal Logic diff --git a/src/inc/routes/register.mjs b/src/inc/routes/register.mjs index cb54aa0..432d7e3 100644 --- a/src/inc/routes/register.mjs +++ b/src/inc/routes/register.mjs @@ -47,7 +47,7 @@ export default (router, tpl) => { const newUser = await db` insert into "user" ("login", "password", "user", "created_at", "admin") - values (${username.toLowerCase()}, ${hash}, ${username}, ${ts}, false) + values (${username.toLowerCase()}, ${hash}, ${username}, to_timestamp(${ts}), false) returning id `; const userId = newUser[0].id; @@ -59,17 +59,17 @@ export default (router, tpl) => { where id = ${tokenRow[0].id} `; - // Get a valid avatar ID (default to 1 or whatever exists) - const avatarRow = await db`select id from items limit 1`; - const avatarId = avatarRow.length > 0 ? avatarRow[0].id : 1; // Fallback to 1, though checking length is safer + // Get a valid avatar ID (default to 1) + const avatarRow = await db`select id from items where id = 1`; + const avatarId = avatarRow.length > 0 ? 1 : (await db`select id from items limit 1`)[0].id; await db` insert into user_options (user_id, mode, theme, fullscreen, avatar) - values (${userId}, 0, 'f0ck', 0, ${avatarId}) + values (${userId}, 3, 'amoled', 0, ${avatarId}) `; - // Redirect to login - return res.writeHead(302, { "Location": "/login" }).end(); + // Redirect to home with login success message + return res.writeHead(302, { "Location": "/?login=success" }).end(); }); return router;