feat: MC Report System - MySQL + Express + Vanilla JS SPA
This commit is contained in:
69
public/js/pages/register.js
Normal file
69
public/js/pages/register.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const RegisterPage = {
|
||||
captcha: null,
|
||||
|
||||
async render() {
|
||||
try { this.captcha = await API.get('/captcha'); } catch { this.captcha = null; }
|
||||
return `
|
||||
<div class="pub-card wide" style="background:white;border-radius:16px;padding:36px 32px;width:540px;max-width:90vw;box-shadow:0 20px 60px rgba(0,0,0,.35)">
|
||||
<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="email" id="re" required placeholder="接收通知"></div>
|
||||
</div>
|
||||
<div class="grid-2">
|
||||
<div class="form-group"><label>游戏名称 *</label><input id="rgn" required placeholder="Minecraft ID"></div>
|
||||
<div class="form-group"><label>游戏UID *</label><input id="rgu" required placeholder="游戏唯一ID"></div>
|
||||
</div>
|
||||
<div class="form-group"><label>密码 *</label><input type="password" id="rp" required placeholder="至少6位"></div>
|
||||
${this.captcha ? `
|
||||
<div class="form-group" style="display:flex;align-items:center;gap:10px">
|
||||
<div style="flex-shrink:0;background:var(--g100);padding:6px 14px;border-radius:var(--r);font-weight:700;font-size:16px;letter-spacing:1px;user-select:none" id="captcha-q">${this.captcha.question}</div>
|
||||
<input type="text" id="captcha-a" placeholder="输入答案" required style="max-width:100px">
|
||||
<input type="hidden" id="captcha-id" value="${this.captcha.id}">
|
||||
</div>` : ''}
|
||||
<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-user-plus"></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('reg-form').addEventListener('submit', async e => {
|
||||
e.preventDefault();
|
||||
const btn = e.target.querySelector('button');
|
||||
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(),
|
||||
game_uid: document.getElementById('rgu').value.trim(),
|
||||
captcha_id: document.getElementById('captcha-id')?.value,
|
||||
captcha_answer: document.getElementById('captcha-a')?.value.trim(),
|
||||
});
|
||||
ok.textContent = '注册成功!请查收验证邮件(如SMTP未配置则自动激活)';
|
||||
ok.classList.remove('hidden');
|
||||
btn.innerHTML = '<i class="fas fa-user-plus"></i> 注册';
|
||||
btn.disabled = false;
|
||||
setTimeout(() => location.hash = '#/login', 3000);
|
||||
} catch (ex) {
|
||||
err.textContent = ex.message;
|
||||
err.classList.remove('hidden');
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fas fa-user-plus"></i> 注册';
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user