Files
MC_Report/public/js/pages/register.js
canglan cb5847d650 feat: game UID fully internal + remove multi-identity copy
- game_uid is now an internal param: auto-generated server-side
  (U + 12 hex) on register/bind-identity/install/admin-create/external
  register; player-supplied game_uid ignored
- Removed all player-facing UID inputs: register page, install page,
  identity bind modal, ticket-create 'your UID' field
- Removed player-facing UID display: identity table column,
  ticket detail/tracking reporter UID
- Removed '同一账号可绑定网易端 + 皮肤站身份' / '可绑定多个来源身份' copy
- Kept target_game_uid (reported player) and admin panel UID management
- settings-page skin-site placeholder updated
2026-08-21 21:52:40 +08:00

135 lines
6.5 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 RegisterPage = {
captcha: null,
codeId: null,
async mount() {
// 动态加载来源下拉(不设默认来源)
U.sources().then(list => {
const sel = document.getElementById('rs');
if (sel) {
sel.innerHTML = '<option value="">不指定</option>' + list.map(s => `<option value="${U.esc(s.code)}">${U.esc(s.label)}</option>`).join('');
this.toggleSource();
}
}).catch(()=>{});
},
async render() {
try { this.captcha = await API.get('/captcha'); } catch { this.captcha = null; }
return `
<div class="pub-card wide">
<div class="logo"><i class="fas fa-user-plus"></i><h2>创建账号</h2><p>加入MC举报系统</p></div>
<form id="reg-form">
<div class="grid-2">
<div class="form-group"><label>站点用户名</label><input id="ru" required placeholder="用于登录"></div>
<div class="form-group"><label>登录密码</label><input type="password" id="rp" required placeholder="至少6位"></div>
</div>
<div class="grid-2">
<div class="form-group"><label>帐号来源</label><select id="rs" onchange="RegisterPage.toggleSource()"><option value="">加载中...</option></select></div>
<div class="form-group"><label id="rs-label1">游戏名称</label><input id="rgn" required placeholder="Minecraft ID"></div>
</div>
${this.captcha ? `
<div class="form-group"><label>人机验证</label>
<div style="display:flex;align-items:center;gap:10px">
<input type="text" id="captcha-a" placeholder="输入图片字符" required style="flex:1">
<div id="captcha-img" style="flex-shrink:0;border:1px solid var(--g200);border-radius:var(--r);overflow:hidden;cursor:pointer" onclick="RegisterPage.refreshCaptcha()" title="点击刷新">${this.captcha.svg}</div>
<input type="hidden" id="captcha-id" value="${this.captcha.id}">
</div>
</div>` : ''}
<div class="form-group"><label>邮箱</label>
<div style="display:flex;gap:8px">
<input type="email" id="re" required placeholder="用于接收验证码" style="flex:1">
<button type="button" class="btn btn-o btn-sm" id="send-code-btn" style="white-space:nowrap">发送验证码</button>
</div>
</div>
<div class="form-group"><label>邮箱验证码</label>
<input id="vf-code" placeholder="6位数字" maxlength="6" pattern="[0-9]{6}" style="margin-bottom:8px">
<div id="regerr" class="alert alert-e hidden"></div>
<div id="regok" class="alert alert-s hidden"></div>
<button type="submit" class="btn btn-p btn-lg w-full"><i class="fas fa-check"></i> 完成注册</button>
</form>
<div style="margin-top:14px;text-align:center;font-size:13px">
<a href="#/login" style="color:var(--p);text-decoration:none;font-weight:600">已有账号?登录</a>
<span style="color:var(--g4);margin:0 10px">|</span>
<a href="#/home" style="color:var(--g5);text-decoration:none">匿名提交</a>
</div>
</div>`;
},
toggleSource() {
const src = document.getElementById('rs').value;
document.getElementById('rs-label1').textContent = '游戏名称';
},
async refreshCaptcha() {
try { const c = await API.get('/captcha'); document.getElementById('captcha-img').innerHTML = c.svg; document.getElementById('captcha-id').value = c.id; document.getElementById('captcha-a').value = ''; } catch {}
},
mount() {
this.toggleSource();
document.getElementById('send-code-btn').addEventListener('click', async () => {
const captcha = document.getElementById('captcha-a');
if (captcha && !captcha.value.trim()) { alert('请先完成人机验证'); return; }
const email = document.getElementById('re').value.trim();
if (!email) { alert('请先填写邮箱'); return; }
const btn = document.getElementById('send-code-btn');
btn.disabled = true; btn.textContent = '发送中...';
try {
const r = await API.post('/auth/send-verify-code', { email });
this.codeId = r.code_id;
if (r.dev) alert('验证码: ' + r.code);
btn.textContent = '\u2713 已发送';
document.getElementById('vf-code').focus();
} catch(ex) { alert(ex.message); btn.disabled = false; btn.textContent = '发送验证码'; }
});
document.getElementById('reg-form').addEventListener('submit', async e => {
e.preventDefault();
const btn = e.target.querySelector('button[type="submit"]');
const err = document.getElementById('regerr'); const ok = document.getElementById('regok');
err.classList.add('hidden'); ok.classList.add('hidden');
btn.disabled = true; btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 注册中...';
try {
await Auth.register({
username: document.getElementById('ru').value.trim(), password: document.getElementById('rp').value,
email: document.getElementById('re').value.trim(), game_name: document.getElementById('rgn').value.trim(),
source: document.getElementById('rs').value,
captcha_id: document.getElementById('captcha-id')?.value,
captcha_answer: document.getElementById('captcha-a')?.value.trim(),
code_id: this.codeId, code: document.getElementById('vf-code').value.trim(),
});
ok.textContent = '注册成功!即将跳转登录...'; ok.classList.remove('hidden');
setTimeout(() => location.hash = '#/login', 2000);
} catch (ex) {
err.textContent = ex.message; err.classList.remove('hidden');
btn.disabled = false; btn.innerHTML = '<i class="fas fa-check"></i> 完成注册';
}
});
}
};