Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
78 lines (78 loc) · 3.01 KB
/
Copy pathindex.html
File metadata and controls
78 lines (78 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Class 2 Forum 登录中心</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="main-wrap">
<div class="card" style="width:360px;">
<div class="logo-wrap">
<div class="logo-dot"></div>
<div>
<div class="logo-text-main">Class 2 Forum</div>
<div class="logo-sub">安全 · 轻量 · Cloudflare 驱动</div>
</div>
</div>
<h1 id="formTitle">🔐 登录论坛</h1>
<div id="loginForm" class="form">
<input id="loginUser" class="input" placeholder="用户名 / 邮箱 / 手机号">
<input id="loginPass" class="input" type="password" placeholder="密码">
<button class="btn" id="loginBtn">登录</button>
<div class="switcher" id="toRegister">还没有账号?点击注册 →</div>
</div>
<div id="registerForm" class="form hidden">
<input id="regName" class="input" placeholder="用户名">
<input id="regEmail" class="input" placeholder="邮箱(可选)">
<input id="regPhone" class="input" placeholder="手机号(可选)">
<input id="regPass" class="input" type="password" placeholder="密码">
<button class="btn ok" id="regBtn">注册</button>
<div class="switcher" id="toLogin">← 返回登录</div>
</div>
<div class="small">管理员账号仅在后端初始化,不会在前端显示。上线后请尽快修改管理员密码。</div>
</div>
</div>
<script src="app.js"></script>
<script>
const loginForm=document.getElementById('loginForm');
const registerForm=document.getElementById('registerForm');
const titleEl=document.getElementById('formTitle');
document.getElementById('toRegister').onclick=()=>{
loginForm.classList.add('hidden');
registerForm.classList.remove('hidden');
titleEl.textContent='🧾 注册新账户';
};
document.getElementById('toLogin').onclick=()=>{
registerForm.classList.add('hidden');
loginForm.classList.remove('hidden');
titleEl.textContent='🔐 登录论坛';
};
window.addEventListener('DOMContentLoaded',()=>{
const $=id=>document.getElementById(id);
$('loginBtn').onclick=async()=>{
const ident=$('loginUser').value.trim();
const pass=$('loginPass').value;
if(!ident||!pass)return alert('请输入账号和密码');
try{
const r=await C2.login(ident,pass);
C2.setMe(r.user);
location.href=r.user.role==='管理员'?'admin.html':'forum.html';
}catch(e){alert(e.message||'登录失败');}
};
$('regBtn').onclick=async()=>{
const u=$('regName').value.trim();
const e=$('regEmail').value.trim();
const p=$('regPhone').value.trim();
const pwd=$('regPass').value;
if(!u||!pwd)return alert('用户名和密码必填');
try{
await C2.register({username:u,email:e,phone:p,password:pwd});
alert('注册成功,请登录');document.getElementById('toLogin').click();
}catch(err){alert(err.message||'注册失败');}
};
});
</script>
</body>
</html>