fix: 修复帖子详情页6处 /login 路径错误

- posts/show.html 中所有 /login 跳转改为 /auth/login
- 覆盖评论登录提示、点赞/反对/收藏 401 跳转
This commit is contained in:
2026-06-02 15:17:35 +08:00
parent b9d90fe7ec
commit c1ad8a0121

View File

@ -126,7 +126,7 @@
</div> </div>
{{else}} {{else}}
<div class="comment-login-hint"> <div class="comment-login-hint">
<a href="/login?redirect=/posts/{{$.Post.ID}}">登录</a> 后参与评论 <a href="/auth/login?redirect=/posts/{{$.Post.ID}}">登录</a> 后参与评论
</div> </div>
{{end}} {{end}}
@ -324,7 +324,7 @@
headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrfToken } headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrfToken }
}) })
.then(function(r) { .then(function(r) {
if (r.status === 401) { window.location.href = '/login?redirect=/posts/' + postId; return null; } if (r.status === 401) { window.location.href = '/auth/login?redirect=/posts/' + postId; return null; }
return r.json(); return r.json();
}) })
.then(function(d) { .then(function(d) {
@ -346,7 +346,7 @@
headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrfToken } headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrfToken }
}) })
.then(function(r) { .then(function(r) {
if (r.status === 401) { window.location.href = '/login?redirect=/posts/' + postId; return null; } if (r.status === 401) { window.location.href = '/auth/login?redirect=/posts/' + postId; return null; }
return r.json(); return r.json();
}) })
.then(function(d) { .then(function(d) {
@ -388,7 +388,7 @@
if (csrfToken) opts.headers['X-CSRF-Token'] = csrfToken; if (csrfToken) opts.headers['X-CSRF-Token'] = csrfToken;
if (data) opts.body = JSON.stringify(data); if (data) opts.body = JSON.stringify(data);
return fetch(url, opts).then(function(r) { return fetch(url, opts).then(function(r) {
if (r.status === 401) { window.location.href = '/login?redirect=/posts/' + postId; throw new Error('unauthorized'); } if (r.status === 401) { window.location.href = '/auth/login?redirect=/posts/' + postId; throw new Error('unauthorized'); }
return r.json(); return r.json();
}); });
} }
@ -470,7 +470,7 @@
// 无弹窗回退(未登录跳转) // 无弹窗回退(未登录跳转)
function handleNoModal() { function handleNoModal() {
if (!csrfToken) { if (!csrfToken) {
window.location.href = '/login?redirect=/posts/' + postId; window.location.href = '/auth/login?redirect=/posts/' + postId;
return; return;
} }
// 无弹窗兜底:直接 toggle // 无弹窗兜底:直接 toggle
@ -571,7 +571,7 @@
// 事件:点击收藏按钮 → 打开弹窗 // 事件:点击收藏按钮 → 打开弹窗
favBtn.addEventListener('click', function() { favBtn.addEventListener('click', function() {
if (!csrfToken) { window.location.href = '/login?redirect=/posts/' + postId; return; } if (!csrfToken) { window.location.href = '/auth/login?redirect=/posts/' + postId; return; }
showModal(); showModal();
}); });