feat: 6-digit email verification code, fix missing script+route includes

This commit is contained in:
2026-07-17 00:34:47 +08:00
parent bfc63a8194
commit ead50beccd
4 changed files with 44 additions and 20 deletions

View File

@@ -57,6 +57,8 @@
<script src="js/pages/install.js"></script>
<script src="js/pages/login.js"></script>
<script src="js/pages/register.js"></script>
<script src="js/pages/forgot.js"></script>
<script src="js/pages/verify.js"></script>
<script src="js/pages/home.js"></script>
<script src="js/pages/dashboard.js"></script>
<script src="js/pages/tickets.js"></script>

View File

@@ -62,17 +62,13 @@ const App = {
const param = parts.slice(1).join('/');
if (page === 'verify') {
const params = new URLSearchParams((location.hash.split('?')[1] || ''));
const token = params.get('token');
if (token) {
API.get(`/auth/verify-email?token=${token}`).then(r => { alert(r.message || '验证成功'); location.hash = '#/login'; }).catch(e => { alert(e.message); location.hash = '#/home'; });
}
this.showPublic('verify');
return;
}
if (page === 'install') { this.showPublic('install'); return; }
if (page === 'home') { this.showPublic('home', param); return; }
if (page === 'login' || page === 'register') { this.showPublic(page); return; }
if (page === 'login' || page === 'register' || page === 'forgot' || page === 'reset') { this.showPublic(page); return; }
if (!Auth.logged()) { location.hash = '#/login'; return; }
this.showLayout();
@@ -184,6 +180,9 @@ window.LoginPage = LoginPage;
window.RegisterPage = RegisterPage;
window.HomePage = HomePage;
window.InstallPage = InstallPage;
window.ForgotPage = ForgotPage;
window.ResetPage = ResetPage;
window.VerifyPage = VerifyPage;
window.U = U;
window.Auth = Auth;
window.API = API;

26
public/js/pages/verify.js Normal file
View File

@@ -0,0 +1,26 @@
const VerifyPage = {
async render() {
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() {
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');
}
});
}
};