diff --git a/js/app.js b/js/app.js
index 072dfa8..10191f2 100644
--- a/js/app.js
+++ b/js/app.js
@@ -512,7 +512,7 @@ async function renderMessagesPage() {
}
// ============================================================
-// ⚙️ 设置页面(含头像上传)
+// ⚙️ 设置页面(含头像上传和恢复码管理)
// ============================================================
async function renderSettingsPage() {
@@ -530,6 +530,13 @@ async function renderSettingsPage() {
const userPosts = await apiFetch('/posts?user_id=' + user.id);
const postCount = userPosts.data ? userPosts.data.length : 0;
+ // 获取恢复码数量
+ let recoveryCount = 0;
+ try {
+ const countData = await API.getRecoveryCodesCount();
+ recoveryCount = countData.count || 0;
+ } catch (e) {}
+
container.innerHTML = `
+
🔑 恢复码
+
+ 请妥善保存以下恢复码。当你忘记密码时,可以使用它们重置密码。
+ 每个恢复码只能使用一次。
+
+
${codesHtml}
+
+
+
+
+
+
+ `;
+
+ modal.style.display = 'flex';
+ modal.classList.add('active');
+
+ document.getElementById('closeRecoveryCodesBtn').addEventListener('click', function() {
+ modal.remove();
+ });
+
+ document.getElementById('copyRecoveryCodesBtn').addEventListener('click', function() {
+ const text = codes.join('\n');
+ navigator.clipboard.writeText(text).then(() => {
+ document.getElementById('copyStatus').textContent = '✅ 已复制到剪贴板';
+ }).catch(() => {
+ const textarea = document.createElement('textarea');
+ textarea.value = text;
+ document.body.appendChild(textarea);
+ textarea.select();
+ document.execCommand('copy');
+ textarea.remove();
+ document.getElementById('copyStatus').textContent = '✅ 已复制到剪贴板';
+ });
+ });
+
+ modal.addEventListener('click', function(e) {
+ if (e.target === this) modal.remove();
+ });
+}
+
// ============================================================
// 🚀 初始化
// ============================================================
@@ -898,6 +1016,49 @@ async function init() {
});
});
+ // 忘记密码事件
+ const forgotLink = document.getElementById('forgotPasswordLink');
+ if (forgotLink) {
+ forgotLink.addEventListener('click', function(e) {
+ e.preventDefault();
+ document.getElementById('forgotPasswordModal').classList.add('active');
+ document.getElementById('resetStatus').textContent = '';
+ });
+ }
+
+ document.getElementById('resetPasswordSubmit').addEventListener('click', async function() {
+ const email = document.getElementById('resetEmail').value.trim();
+ const code = document.getElementById('resetRecoveryCode').value.trim().toUpperCase();
+ const newPassword = document.getElementById('resetNewPassword').value;
+ const statusEl = document.getElementById('resetStatus');
+
+ if (!email || !code || !newPassword) {
+ statusEl.textContent = '请填写完整信息';
+ statusEl.style.color = '#ef4444';
+ return;
+ }
+ if (newPassword.length < 6) {
+ statusEl.textContent = '密码至少6位';
+ statusEl.style.color = '#ef4444';
+ return;
+ }
+
+ try {
+ await API.resetPassword(email, code, newPassword);
+ statusEl.textContent = '✅ 重置成功!请登录';
+ statusEl.style.color = '#22c55e';
+ setTimeout(() => {
+ document.getElementById('forgotPasswordModal').classList.remove('active');
+ document.getElementById('resetEmail').value = '';
+ document.getElementById('resetRecoveryCode').value = '';
+ document.getElementById('resetNewPassword').value = '';
+ }, 1500);
+ } catch (err) {
+ statusEl.textContent = '❌ ' + err.message;
+ statusEl.style.color = '#ef4444';
+ }
+ });
+
window.addEventListener('popstate', function(e) {
const state = e.state || {};
const page = state.page || 'feed';