'use client'; import { useEffect, useState, type FormEvent } from 'react'; export default function AccountPage() { const [mode,setMode]=useState('login');const [user,setUser]=useState<{email:string}|null>(null); const [message,setMessage]=useState('');const [busy,setBusy]=useState(false);const [token,setToken]=useState(''); async function refresh(){try{const r=await fetch('/api/account/session');const data=await r.json();if(r.ok)setUser(data.user);else setMessage(data.error);}catch{setMessage('暂时无法连接账户服务');}} useEffect(()=>{void refresh();const u=new URL(window.location.href);setToken(u.searchParams.get('verify')||'');if(u.searchParams.has('verify'))window.history.replaceState({},'', '/account');},[]); async function action(name:string,body:object={}) {setBusy(true);setMessage('');try{const r=await fetch('/api/account/'+name,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});const d=await r.json();setMessage(d.error||d.message||'操作成功');if(r.ok){if(name==='verify')setToken('');await refresh();}}catch{setMessage('网络异常,请稍后重试');}finally{setBusy(false);}} function submit(e:FormEvent){e.preventDefault();const f=new FormData(e.currentTarget);void action(mode,{email:f.get('email'),password:f.get('password')});} const button={padding:'12px 20px',border:'1px solid #394b43',borderRadius:12,cursor:'pointer',background:'#173d30',color:'white'}; return
← 返回知识站

你的知识站账户

用邮箱保存你的身份。邮箱账户与管理员动态码权限独立。

{token&&

确认邮箱验证

点击后完成验证,再使用邮箱和密码登录。

} {user?

已登录

{user.email}

邮箱已验证

:<>
密码至少 12 个字符。注册后需先验证邮箱;验证链接有效期 30 分钟。
}

{message}

; }