fix: resolve conflicts for PR #14
This commit is contained in:
commit
5314d60f53
30 files changed
+1755
-848
No files matched your search
@@ -35,10 +35,10 @@ const API = {
|
||||
return data;
|
||||
},
|
||||
|
||||
async register(email, password, username) {
|
||||
async register(email, password, username, bootstrapToken = '') {
|
||||
const data = await apiFetch('/auth/register', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ email, password, username })
|
||||
body: JSON.stringify({ email, password, username, bootstrap_token: bootstrapToken || undefined })
|
||||
});
|
||||
if (data.error) throw new Error(data.error);
|
||||
return data;
|
||||
@@ -227,14 +227,6 @@ const API = {
|
||||
return data;
|
||||
},
|
||||
|
||||
async logEvent(action) {
|
||||
try {
|
||||
await apiFetch('/event-logs', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ action })
|
||||
});
|
||||
} catch (e) { /* 静默失败 */ }
|
||||
},
|
||||
|
||||
// ============================================================
|
||||
// 论坛设置
|
||||
|
||||
@@ -490,7 +490,7 @@ function showCustomPage(pageName) {
|
||||
API.getCustomPage(pageName).then(page => {
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.style.cssText = 'width:100%;min-height:70vh;border:none;border-radius:8px;background:var(--surface);';
|
||||
iframe.sandbox = 'allow-scripts allow-modals';
|
||||
iframe.sandbox = 'allow-scripts allow-modals allow-top-navigation allow-same-origin allow-popups';
|
||||
iframe.srcdoc = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -843,8 +843,12 @@ async function renderSettingsPage(tab = 'profile') {
|
||||
await API.changePassword(oldPassword, newPassword);
|
||||
document.getElementById('changeOldPassword').value = '';
|
||||
document.getElementById('changeNewPassword').value = '';
|
||||
statusEl.textContent = getIcon('success') + ' 密码修改成功!';
|
||||
statusEl.textContent = getIcon('success') + ' 密码修改成功,正在返回登录页…';
|
||||
statusEl.style.color = '#22c55e';
|
||||
localStorage.removeItem('token');
|
||||
currentUser = null;
|
||||
renderNav();
|
||||
setTimeout(() => switchPage('login'), 800);
|
||||
} catch (err) {
|
||||
statusEl.textContent = getIcon('error') + ' ' + err.message;
|
||||
statusEl.style.color = '#ef4444';
|
||||
@@ -867,9 +871,12 @@ async function renderSettingsPage(tab = 'profile') {
|
||||
await API.changeEmail(password, newEmail);
|
||||
document.getElementById('changeEmailPassword').value = '';
|
||||
document.getElementById('changeNewEmail').value = '';
|
||||
currentUser.email = newEmail;
|
||||
statusEl.textContent = getIcon('success') + ' 邮箱修改成功!';
|
||||
statusEl.textContent = getIcon('success') + ' 邮箱修改成功,正在返回登录页…';
|
||||
statusEl.style.color = '#22c55e';
|
||||
localStorage.removeItem('token');
|
||||
currentUser = null;
|
||||
renderNav();
|
||||
setTimeout(() => switchPage('login'), 800);
|
||||
} catch (err) {
|
||||
statusEl.textContent = getIcon('error') + ' ' + err.message;
|
||||
statusEl.style.color = '#ef4444';
|
||||
@@ -1123,7 +1130,7 @@ async function init() {
|
||||
try {
|
||||
const user = await API.getMe();
|
||||
currentUser = user;
|
||||
API.logEvent('login').catch(() => {});
|
||||
|
||||
} catch (e) {
|
||||
token = null;
|
||||
localStorage.removeItem('forumlify-token');
|
||||
@@ -1278,7 +1285,7 @@ async function init() {
|
||||
images.push(uploaded.url);
|
||||
}
|
||||
await API.createPost(title, content, images);
|
||||
API.logEvent('create_post').catch(() => {});
|
||||
|
||||
alert('发布成功!');
|
||||
clearSelectedImages();
|
||||
switchPage('feed');
|
||||
|
||||
+3
-3
@@ -18,7 +18,6 @@ document.getElementById('loginSubmit').addEventListener('click', async () => {
|
||||
document.getElementById('loginPassword').value = '';
|
||||
if (result.user) {
|
||||
currentUser = result.user;
|
||||
API.logEvent('login').catch(() => {});
|
||||
renderNav();
|
||||
if (currentPage === 'admin' && currentUser.role !== 'admin') {
|
||||
switchPage('feed');
|
||||
@@ -42,13 +41,14 @@ document.getElementById('registerSubmit').addEventListener('click', async () =>
|
||||
const username = document.getElementById('regUsername').value.trim();
|
||||
const email = document.getElementById('regEmail').value.trim();
|
||||
const password = document.getElementById('regPassword').value;
|
||||
const bootstrapToken = document.getElementById('regBootstrapToken').value.trim();
|
||||
const captchaInput = document.getElementById('regCaptchaInput').value.trim();
|
||||
const captchaAnswer = parseInt(document.getElementById('regCaptchaInput').dataset.answer);
|
||||
if (!username || !email || !password) { alert('请填写完整信息'); return; }
|
||||
if (password.length < 6) { alert('密码至少6位'); return; }
|
||||
if (parseInt(captchaInput) !== captchaAnswer) { alert('验证码错误,请重新计算'); refreshCaptcha('reg'); return; }
|
||||
try {
|
||||
await API.register(email, password, username);
|
||||
await API.register(email, password, username, bootstrapToken);
|
||||
} catch (err) {
|
||||
alert('注册失败:' + err.message);
|
||||
return;
|
||||
@@ -58,12 +58,12 @@ document.getElementById('registerSubmit').addEventListener('click', async () =>
|
||||
document.getElementById('regUsername').value = '';
|
||||
document.getElementById('regEmail').value = '';
|
||||
document.getElementById('regPassword').value = '';
|
||||
document.getElementById('regBootstrapToken').value = '';
|
||||
document.getElementById('regCaptchaInput').value = '';
|
||||
|
||||
try {
|
||||
await API.login(email, password);
|
||||
currentUser = await API.getMe();
|
||||
API.logEvent('register').catch(() => {});
|
||||
renderNav();
|
||||
|
||||
if (currentPage === 'admin' && currentUser.role !== 'admin') {
|
||||
|
||||
+1
-1
@@ -228,7 +228,7 @@ async function handleReplySubmit(postId) {
|
||||
if (parseInt(captchaInput) !== captchaAnswer) { alert('验证码错误,请重新计算'); refreshCaptcha('reply'); return; }
|
||||
try {
|
||||
await API.createReply(postId, content);
|
||||
API.logEvent('create_reply').catch(() => {});
|
||||
|
||||
renderPostDetail(postId);
|
||||
if (currentPage === 'feed') {
|
||||
renderFeed();
|
||||
|
||||
Reference in new issue
Block a user