feat: 登录验证 + 邀请码注册 + 用量监控后台
- 新增用户认证系统(登录/登出/邀请码注册) - 新增管理后台(邀请码管理/用户管理/使用记录/用量统计) - 合成接口加登录验证,每次调用记录用户和稿件内容 - SQLite存储用户数据和使用日志 - 默认admin账号: simonkoson Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+33
-1
@@ -358,7 +358,39 @@ elements.audioDisplay.addEventListener('click', () => {
|
||||
if (state.generatedAudio && !state.isPlaying) { togglePlay(); }
|
||||
});
|
||||
|
||||
function init() {
|
||||
async function init() {
|
||||
// 登录检测
|
||||
try {
|
||||
const res = await fetch('/api/me');
|
||||
if (!res.ok) {
|
||||
window.location.href = '/login.html';
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
const user = data.user;
|
||||
|
||||
// 在 header 右侧显示用户信息
|
||||
const headerInfo = document.querySelector('.header-info');
|
||||
headerInfo.innerHTML = `
|
||||
<span class="engine-badge" id="engineBadge">蓝皓</span>
|
||||
<span class="user-info">
|
||||
${user.display_name}
|
||||
${user.role === 'admin' ? '<a href="/admin.html" class="admin-link">管理后台</a>' : ''}
|
||||
<a href="#" id="logoutLink" class="logout-link">退出</a>
|
||||
</span>
|
||||
`;
|
||||
|
||||
document.getElementById('logoutLink').addEventListener('click', async (e) => {
|
||||
e.preventDefault();
|
||||
await fetch('/api/logout', { method: 'POST' });
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
window.location.href = '/login.html';
|
||||
return;
|
||||
}
|
||||
|
||||
updateCharCount();
|
||||
updateSliderDisplay();
|
||||
const savedHistory = localStorage.getItem('tts_history');
|
||||
|
||||
Reference in New Issue
Block a user