Fix: redirect login/signup

This commit is contained in:
hyzen
2026-06-09 01:33:09 +05:30
parent 45551f0310
commit 4094266e78
49 changed files with 365 additions and 134 deletions

View File

@@ -70,7 +70,11 @@
</div>
<!-- Subscribe dropdown -->
<div class="rss-subscribe">
<button class="rss-subscribe__btn" aria-label="Subscribe via RSS" title="Subscribe via RSS">
<button
class="rss-subscribe__btn"
aria-label="Subscribe via RSS"
title="Subscribe via RSS"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
@@ -86,8 +90,18 @@
<span>Subscribe</span>
</button>
<div class="rss-subscribe__dropdown">
<button class="rss-subscribe__item" data-rss-url="https://freedoms4.org/index.xml">All updates</button>
<button class="rss-subscribe__item" data-rss-url="https://freedoms4.org/blog/index.xml">Blog posts</button>
<button
class="rss-subscribe__item"
data-rss-url="https://freedoms4.org/index.xml"
>
All updates
</button>
<button
class="rss-subscribe__item"
data-rss-url="https://freedoms4.org/blog/index.xml"
>
Blog posts
</button>
</div>
</div>
</div>
@@ -97,5 +111,18 @@
<main class="main">{{ block "main" . }}{{ end }}</main>
<footer class="footer">{{ partial "footer.html" . }}</footer>
{{ partial "body/body-end.html" . }}
<script>
(function () {
var path = window.location.pathname;
if (path === '/login/' || path === '/signup/') return;
document
.querySelectorAll('a[href="/login/"], a[href="/signup/"]')
.forEach(function (a) {
a.addEventListener('click', function () {
sessionStorage.setItem('f4_login_next', path);
});
});
})();
</script>
</body>
</html>

View File

@@ -93,6 +93,38 @@
(function () {
var BACKEND = 'https://backend.freedoms4.org/auth.php';
// ── Already logged in ──
if (localStorage.getItem('f4_username')) {
document.getElementById('auth-message').textContent = 'You are already logged in!';
document.getElementById('auth-message').className =
'auth-message auth-message--success';
document.getElementById('auth-message').style.display = 'block';
document.getElementById('login-form').style.display = 'none';
setTimeout(function () {
window.location.href = '/';
}, 1500);
return;
}
// ── Remember where to go after login ──
(function () {
var params = new URLSearchParams(window.location.search);
var next = params.get('next');
if (next && next.startsWith('/')) {
sessionStorage.setItem('f4_login_next', next);
} else if (!sessionStorage.getItem('f4_login_next') && document.referrer) {
try {
var refUrl = new URL(document.referrer);
if (refUrl.hostname === window.location.hostname) {
var p = refUrl.pathname;
if (p !== '/login/' && p !== '/signup/') {
sessionStorage.setItem('f4_login_next', p);
}
}
} catch (e) {}
}
})();
var form = document.getElementById('login-form');
var msgBox = document.getElementById('auth-message');
var submitBtn = document.getElementById('login-submit');
@@ -142,7 +174,10 @@
showMsg('Logged in successfully! Redirecting\u2026', 'success');
localStorage.setItem('f4_username', username);
setTimeout(function () {
window.location.href = data.redirect || '/';
var _next = sessionStorage.getItem('f4_login_next');
sessionStorage.removeItem('f4_login_next');
window.location.href =
_next && _next.startsWith('/') ? _next : data.redirect || '/';
}, 1000);
} else {
showMsg(data.message || 'Login failed. Please try again.', 'error');

View File

@@ -176,6 +176,39 @@
(function () {
var BACKEND = 'https://backend.freedoms4.org/auth.php';
// ── Already logged in ──
if (localStorage.getItem('f4_username')) {
document.getElementById('auth-message').textContent = 'You are already logged in!';
document.getElementById('auth-message').className =
'auth-message auth-message--success';
document.getElementById('auth-message').style.display = 'block';
document.getElementById('signup-form').style.display = 'none';
setTimeout(function () {
window.location.href = '/';
}, 1500);
return;
}
// ── Pass next-page through to login ──
var _signupNext =
new URLSearchParams(window.location.search).get('next') ||
sessionStorage.getItem('f4_login_next') ||
'';
// Save referrer as next-page if not already set and referrer is on this site
if (!_signupNext && document.referrer) {
try {
var _refUrl = new URL(document.referrer);
if (_refUrl.hostname === window.location.hostname) {
var _refPath = _refUrl.pathname;
if (_refPath !== '/login/' && _refPath !== '/signup/') {
_signupNext = _refPath;
sessionStorage.setItem('f4_login_next', _refPath);
}
}
} catch (e) {}
}
var state = { username: '', email: '', password: '' };
var msgBox = document.getElementById('auth-message');
@@ -361,6 +394,10 @@
if (data.success) {
showMsg('Account created! Redirecting to login\u2026', 'success');
setTimeout(function () {
window.location.href =
_signupNext && _signupNext.startsWith('/')
? '/login/?next=' + encodeURIComponent(_signupNext)
: '/login/';
window.location.href = '/login/';
}, 1800);
} else {