- 52 JS files (backend + public/js): header with Copyright (C) 2026 Sea Network Technology Studio Author: CangLan <admin@sea-studio.top> + AGPLv3 notice - idempotent (skips if header present), all syntax-checked
76 lines
3.8 KiB
JavaScript
76 lines
3.8 KiB
JavaScript
/*
|
||
* MC Report System
|
||
* Copyright (C) 2026 Sea Network Technology Studio
|
||
* Author: CangLan <admin@sea-studio.top>
|
||
*
|
||
* This program is free software: you can redistribute it and/or modify
|
||
* it under the terms of the GNU Affero General Public License as published
|
||
* by the Free Software Foundation, either version 3 of the License, or
|
||
* (at your option) any later version.
|
||
*
|
||
* This program is distributed in the hope that it will be useful,
|
||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
* GNU Affero General Public License for more details.
|
||
*
|
||
* You should have received a copy of the GNU Affero General Public License
|
||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
const ForgotPage = {
|
||
async render() {
|
||
return `<div class="pub-card"><div class="logo"><i class="fas fa-key"></i><h2>忘记密码</h2><p>输入注册邮箱获取重置链接</p></div>
|
||
<form id="forgot-form"><div class="form-group"><input type="email" id="fg-email" placeholder="注册邮箱" required></div>
|
||
<div id="fg-msg" class="hidden"></div>
|
||
<button type="submit" class="btn btn-p btn-lg w-full"><i class="fas fa-paper-plane"></i> 发送重置链接</button></form>
|
||
<div style="margin-top:14px;text-align:center;font-size:13px"><a href="#/login" style="color:var(--p);text-decoration:none">返回登录</a></div>
|
||
</div>`;
|
||
},
|
||
mount() {
|
||
document.getElementById('forgot-form').addEventListener('submit', async e => {
|
||
e.preventDefault();
|
||
try {
|
||
await API.post('/auth/forgot-password', { email: document.getElementById('fg-email').value });
|
||
const el = document.getElementById('fg-msg');
|
||
el.className = 'alert alert-s';
|
||
el.textContent = '如果邮箱已注册,重置链接已发送';
|
||
el.classList.remove('hidden');
|
||
} catch(ex) { alert(ex.message); }
|
||
});
|
||
}
|
||
};
|
||
|
||
const ResetPage = {
|
||
async render() {
|
||
const params = new URLSearchParams((location.hash.split('?')[1] || ''));
|
||
const token = params.get('token');
|
||
if (!token) return `<div class="pub-card"><div class="logo"><i class="fas fa-exclamation-triangle" style="color:var(--d)"></i><h2>无效链接</h2><p>重置链接无效</p></div><div style="text-align:center;margin-top:14px"><a href="#/login" style="color:var(--p)">返回登录</a></div></div>`;
|
||
return `<div class="pub-card"><div class="logo"><i class="fas fa-lock"></i><h2>重置密码</h2><p>请输入新密码</p></div>
|
||
<form id="reset-form"><div class="form-group"><input type="password" id="rs-pwd" placeholder="新密码(至少6位)" required minlength="6"></div>
|
||
<div id="rs-msg" class="hidden"></div>
|
||
<button type="submit" class="btn btn-p btn-lg w-full"><i class="fas fa-save"></i> 重置密码</button>
|
||
</form><div style="margin-top:14px;text-align:center;font-size:13px"><a href="#/login" style="color:var(--p)">返回登录</a></div></div>`;
|
||
},
|
||
mount() {
|
||
const params = new URLSearchParams((location.hash.split('?')[1] || ''));
|
||
const token = params.get('token');
|
||
if (!token) return;
|
||
document.getElementById('reset-form').addEventListener('submit', async e => {
|
||
e.preventDefault();
|
||
try {
|
||
await API.post('/auth/reset-password', { token, password: document.getElementById('rs-pwd').value });
|
||
const el = document.getElementById('rs-msg');
|
||
el.className = 'alert alert-s';
|
||
el.textContent = '密码重置成功!请登录';
|
||
el.classList.remove('hidden');
|
||
setTimeout(() => location.hash = '#/login', 2000);
|
||
} catch(ex) {
|
||
const el = document.getElementById('rs-msg');
|
||
el.className = 'alert alert-e';
|
||
el.textContent = ex.message;
|
||
el.classList.remove('hidden');
|
||
}
|
||
});
|
||
}
|
||
};
|