Files
MC_Report/public/js/pages/verify.js
canglan 8c5ce78fd0 chore: add AGPLv3 copyright header to all source files
- 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
2026-08-19 20:27:05 +08:00

70 lines
3.2 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 VerifyPage = {
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-envelope"></i><h2>邮箱验证</h2><p>正在验证您的邮箱...</p></div>
<div id="vf-msg" class="alert alert-i">验证中,请稍候...</div>
<div style="margin-top:14px;text-align:center;font-size:13px"><a href="#/login" style="color:var(--p);text-decoration:none">返回登录</a></div>
</div>`;
}
return `<div class="pub-card"><div class="logo"><i class="fas fa-envelope"></i><h2>邮箱验证</h2><p>请输入邮件中的6位验证码</p></div>
<form id="verify-form"><div class="form-group"><input id="vf-code" placeholder="6位验证码" required maxlength="6" minlength="6" pattern="[0-9]{6}" autofocus></div>
<div id="vf-msg" class="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">返回登录</a></div>
</div>`;
},
mount() {
const params = new URLSearchParams((location.hash.split('?')[1] || ''));
const token = params.get('token');
if (token) {
this.verifyToken(token);
return;
}
document.getElementById('verify-form').addEventListener('submit', async e => {
e.preventDefault();
const code = document.getElementById('vf-code').value.trim();
const msg = document.getElementById('vf-msg');
try {
const r = await API.post('/auth/verify-email', { code });
msg.className = 'alert alert-s'; msg.textContent = r.message || '验证成功';
msg.classList.remove('hidden');
setTimeout(() => location.hash = '#/login', 2000);
} catch(ex) {
msg.className = 'alert alert-e'; msg.textContent = ex.message;
msg.classList.remove('hidden');
}
});
},
async verifyToken(token) {
const msg = document.getElementById('vf-msg');
try {
const r = await API.post('/auth/verify-email', { code: token });
msg.className = 'alert alert-s'; msg.textContent = r.message || '验证成功';
setTimeout(() => location.hash = '#/login', 2000);
} catch (ex) {
msg.className = 'alert alert-e'; msg.textContent = ex.message;
}
}
};