Files
MC_Report/public/js/pages/register.js

84 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const RegisterPage = {
captcha: null,
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>åˆå»ºè´¦å<C2A6>·</h2><p>加入MC举报系统</p></div>
<form id="reg-form">
<div class="grid-2">
<div class="form-group"><label>ç«™ç¹ç”¨æˆ·å<C2B7>?*</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>游æˆ<C3A6>å<EFBFBD><C3A5>ç§° *</label><input id="rgn" required placeholder="Minecraft ID"></div>
<div class="form-group"><label>游æˆ<C3A6>UID *</label><input id="rgu" required placeholder="游æˆ<C3A6>唯一ID"></div>
</div>
<div class="form-group"><label>密ç <C3A7> *</label><input type="password" id="rp" required placeholder="至å°6ä½?></div>
${this.captcha ? `
<div class="form-group"><label>验è¯<C3A8>ç ?/label>
<div style="display:flex;align-items:center;gap:10px">
<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="text" id="captcha-a" placeholder="输入图片字符" required style="max-width:100px">
<input type="hidden" id="captcha-id" value="${this.captcha.id}">
</div>
<div class="help">ç¹å‡»å¾ç‰‡åˆ·æ°éªŒè¯<C3A8>ç ?/div>
</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;font-weight:600">已有账å<C2A6>·ï¼Ÿç™»å½?/a>
<span style="color:var(--g4);margin:0 10px">|</span>
<a href="#/home" style="color:var(--g5);text-decoration:none">匿å<C2BF><C3A5>æ<EFBFBD><C3A6>交</a>
</div>
</div>`;
},
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() {
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 = '注册æˆ<C3A6>功ï¼<C3AF>请查收验è¯<C3A8>é®ä»¶ï¼ˆå¦SMTP未é…<C3A9>置则自动激活)';
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> 注册';
}
});
}
};