Files
MC_Report/public/js/pages/forgot.js

57 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
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 ForgotPage = {
async render() {
return `<div class="pub-card"><div class="logo"><i class="fas fa-key"></i><h2>忘记密码</h2><p>输入注册邮箱获取重置链接</p></div>
<form id="forgot-form"><div class="form-group"><input type="email" id="fg-email" placeholder="注册邮箱" required></div>
<div id="fg-msg" class="hidden"></div>
<button type="submit" class="btn btn-p btn-lg w-full"><i class="fas fa-paper-plane"></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('forgot-form').addEventListener('submit', async e => {
e.preventDefault();
try {
await API.post('/auth/forgot-password', { email: document.getElementById('fg-email').value });
const el = document.getElementById('fg-msg');
el.className = 'alert alert-s';
el.textContent = '如果邮箱已注册,重置链接已发送';
el.classList.remove('hidden');
} catch(ex) { alert(ex.message); }
});
}
};
const ResetPage = {
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-exclamation-triangle" style="color:var(--d)"></i><h2>无效链接</h2><p>重置链接无效</p></div><div style="text-align:center;margin-top:14px"><a href="#/login" style="color:var(--p)">返回登录</a></div></div>`;
return `<div class="pub-card"><div class="logo"><i class="fas fa-lock"></i><h2>重置密码</h2><p>请输入新密码</p></div>
<form id="reset-form"><div class="form-group"><input type="password" id="rs-pwd" placeholder="新密码至少6位" required minlength="6"></div>
<div id="rs-msg" class="hidden"></div>
<button type="submit" class="btn btn-p btn-lg w-full"><i class="fas fa-save"></i> 重置密码</button>
</form><div style="margin-top:14px;text-align:center;font-size:13px"><a href="#/login" style="color:var(--p)">返回登录</a></div></div>`;
},
mount() {
const params = new URLSearchParams((location.hash.split('?')[1] || ''));
const token = params.get('token');
if (!token) return;
document.getElementById('reset-form').addEventListener('submit', async e => {
e.preventDefault();
try {
await API.post('/auth/reset-password', { token, password: document.getElementById('rs-pwd').value });
const el = document.getElementById('rs-msg');
el.className = 'alert alert-s';
el.textContent = '密码重置成功!请登录';
el.classList.remove('hidden');
setTimeout(() => location.hash = '#/login', 2000);
} catch(ex) {
const el = document.getElementById('rs-msg');
el.className = 'alert alert-e';
el.textContent = ex.message;
el.classList.remove('hidden');
}
});
}
};