## 新增功能 ### 消息通知中心 (全新模块) - 新增 MessageController / NotificationService / NotificationRepo - SSR 消息页面 (/messages):左侧边栏 + 右侧卡片列表,noindex 元标签 - 通知能力:列表分页、单条标为已读、一键全部标为已读 - 未读数角标 (1/66/99+):侧边栏 + 导航栏铃铛图标 - 导航栏轮询 /api/messages/unread 每 60 秒刷新未读数 - 审核通过/驳回时自动 fire-and-forget 推送通知 ### 密码修改 - ChangePassword:验证当前密码 → 新密码强度校验(8位+字母+数字) → 哈希更新 - 修改后递增 token_version 强制所有设备退登 ### 账号自助注销 - DeleteAccount:验证密码 → 设置 deleted 状态 → 记录原因 → 吊销 JWT - 注销后登录二次确认:Login 检测 deleted → 返回 confirm_restore - ConfirmRestore 恢复账号,重新签发 token - 注销页文案:"账号将在 7 天后正式注销,期间可随时重新登录恢复" ### IP 审计记录 - 注册时记录 RegIP,登录时记录 LastLoginIP + LastLoginAt - clientIP() 支持 X-Forwarded-For / X-Real-IP 反向代理 ### 安全加固 - Login 防时序攻击:用户不存在时仍执行完整 bcrypt 比对 - FindByEmail 改用 Unscoped() 覆盖软删除用户 - 站长 (owner) 不允许自主注销,避免权限体系死锁 ## Bug 修复 1. 注销按钮不触发:JS IIFE 中 profile 代码 return 阻塞了 account 标签页处理器注册 → 拆分为两层 IIFE,profile 放在内层 2. label 缺少 for 属性导致控制台警告 → 全部补充 for 属性 3. 注销后未自动退登:DeleteAccount 只设状态未吊销 JWT → 末尾加 InvalidateSessions 4. 退登后重定向 500 panic:authenticateToken 中 err||versionMismatch 合并判断 在 err=nil 但版本不匹配时返回 (nil,nil) → 拆为两个独立判断 injectUserContext 增加 claims==nil / 类型断言空安全守卫 5. 注销后登录直接提示"登录成功":FindByEmail 默认 scope 排除软删除记录 → 改用 Unscoped() ## 文件变更 - 新建 17 个文件 (消息/审核/站点设置完整模块) - 修改 25 个文件 (认证/设置/中间件/前端) - 统计:+3229 / -161,42 files changed
173 lines
6.8 KiB
HTML
173 lines
6.8 KiB
HTML
{{template "layout/header.html" .}}
|
|
<meta name="robots" content="noindex,nofollow">
|
|
<body>
|
|
|
|
{{template "layout/nav.html" .}}
|
|
|
|
<main class="msg-layout">
|
|
<aside class="msg-sidebar">
|
|
<div class="msg-sidebar-header">
|
|
<h2>消息中心</h2>
|
|
</div>
|
|
<nav class="msg-sidebar-nav">
|
|
<span class="msg-sidebar-item active">
|
|
<svg class="msg-sidebar-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
|
|
全部消息
|
|
{{if .UnreadCount}}
|
|
<span class="msg-sidebar-count">{{.UnreadCount}}</span>
|
|
{{end}}
|
|
</span>
|
|
</nav>
|
|
</aside>
|
|
|
|
<div class="msg-main">
|
|
{{if .Messages}}
|
|
<div class="msg-toolbar">
|
|
{{if .UnreadCount}}
|
|
<button id="markAllReadBtn" class="msg-mark-all-btn">全部标为已读</button>
|
|
{{end}}
|
|
</div>
|
|
<div class="msg-list">
|
|
{{range $i, $m := .Messages}}
|
|
<div class="msg-card{{if not $m.IsRead}} unread{{end}}" data-id="{{$m.ID}}">
|
|
<div class="msg-icon">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="20" height="20"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
|
|
</div>
|
|
<div class="msg-body">
|
|
<div class="msg-title">{{$m.Title}}</div>
|
|
<div class="msg-content">{{$m.Content}}</div>
|
|
<div class="msg-meta">
|
|
<span class="msg-type">{{index $.NotifyTypeNames $m.NotifyType}}</span>
|
|
<span class="msg-time">{{$m.CreatedAt.Format "2006-01-02 15:04"}}</span>
|
|
</div>
|
|
</div>
|
|
{{if not $m.IsRead}}
|
|
<span class="msg-badge"></span>
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
|
|
{{if .TotalPages}}
|
|
<div class="msg-pagination">
|
|
{{if .HasPrev}}
|
|
<a href="/messages?page={{.PrevPage}}" class="msg-page-btn">上一页</a>
|
|
{{else}}
|
|
<span class="msg-page-btn disabled">上一页</span>
|
|
{{end}}
|
|
<span class="msg-page-info">{{.Page}} / {{.TotalPages}}</span>
|
|
{{if .HasNext}}
|
|
<a href="/messages?page={{.NextPage}}" class="msg-page-btn">下一页</a>
|
|
{{else}}
|
|
<span class="msg-page-btn disabled">下一页</span>
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
|
|
{{else}}
|
|
<div class="msg-empty">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" width="48" height="48" class="msg-empty-icon"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><line x1="4" y1="17" x2="20" y2="17"/><line x1="9" y1="11" x2="10" y2="11"/><line x1="14" y1="11" x2="15" y2="11"/></svg>
|
|
<p>暂无消息</p>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
</main>
|
|
|
|
{{template "layout/footer.html" .}}
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
|
|
// ---- 单条标记已读 ----
|
|
var cards = document.querySelectorAll('.msg-card.unread');
|
|
for (var i = 0; i < cards.length; i++) {
|
|
(function (card) {
|
|
card.addEventListener('click', function () {
|
|
var id = card.getAttribute('data-id');
|
|
if (!id) return;
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/api/messages/' + id + '/read', true);
|
|
xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
card.classList.remove('unread');
|
|
var badge = card.querySelector('.msg-badge');
|
|
if (badge) badge.remove();
|
|
updateUnreadCounts();
|
|
}
|
|
};
|
|
xhr.send();
|
|
});
|
|
})(cards[i]);
|
|
}
|
|
|
|
// ---- 全部标为已读 ----
|
|
var markAllBtn = document.getElementById('markAllReadBtn');
|
|
if (markAllBtn) {
|
|
markAllBtn.addEventListener('click', function () {
|
|
markAllBtn.disabled = true;
|
|
markAllBtn.textContent = '处理中...';
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/api/messages/read-all', true);
|
|
xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4) {
|
|
markAllBtn.disabled = false;
|
|
markAllBtn.textContent = '全部标为已读';
|
|
if (xhr.status === 200) {
|
|
// 本地清除所有 unread 样式
|
|
var allCards = document.querySelectorAll('.msg-card.unread');
|
|
for (var j = 0; j < allCards.length; j++) {
|
|
allCards[j].classList.remove('unread');
|
|
var b = allCards[j].querySelector('.msg-badge');
|
|
if (b) b.remove();
|
|
}
|
|
markAllBtn.remove();
|
|
updateUnreadCounts();
|
|
}
|
|
}
|
|
};
|
|
xhr.send();
|
|
});
|
|
}
|
|
|
|
// ---- 更新侧边栏和导航栏未读计数 ----
|
|
function updateUnreadCounts() {
|
|
// 更新侧边栏计数
|
|
var visibleUnread = document.querySelectorAll('.msg-card.unread').length;
|
|
var sidebarCount = document.querySelector('.msg-sidebar-count');
|
|
if (sidebarCount) {
|
|
if (visibleUnread > 0) {
|
|
sidebarCount.textContent = visibleUnread;
|
|
} else {
|
|
sidebarCount.remove();
|
|
}
|
|
} else if (visibleUnread > 0) {
|
|
var sidebarItem = document.querySelector('.msg-sidebar-item.active');
|
|
if (sidebarItem) {
|
|
var el = document.createElement('span');
|
|
el.className = 'msg-sidebar-count';
|
|
el.textContent = visibleUnread;
|
|
sidebarItem.appendChild(el);
|
|
}
|
|
}
|
|
|
|
// 更新导航栏铃铛计数
|
|
var navBadge = document.getElementById('msgBadge');
|
|
if (navBadge) {
|
|
fetch('/api/messages/unread')
|
|
.then(function (res) { return res.json(); })
|
|
.then(function (data) {
|
|
if (data && data.success && data.data) {
|
|
var count = data.data.unread || 0;
|
|
navBadge.textContent = count > 99 ? '99+' : count;
|
|
navBadge.style.display = count > 0 ? 'flex' : 'none';
|
|
}
|
|
})
|
|
.catch(function () {});
|
|
}
|
|
}
|
|
})();
|
|
</script>
|
|
<script src="/static/js/common.js"></script>
|
|
</body>
|
|
</html>
|