diff --git a/accounts/templates/accounts/register.html b/accounts/templates/accounts/register.html index 791cbe9..263d2e8 100644 --- a/accounts/templates/accounts/register.html +++ b/accounts/templates/accounts/register.html @@ -24,6 +24,10 @@ + +
+ + @@ -43,20 +47,36 @@ const code=(document.getElementById('code').value||'').trim(); const email=(document.getElementById('email').value||'').trim(); const username=(document.getElementById('username').value||'').trim(); + const email_code=(document.getElementById('email_code').value||'').trim(); const password=document.getElementById('password').value||''; const confirm=document.getElementById('confirm').value||''; - if(!code||!email||!username||!password){err.textContent='请填写所有字段';return;} + if(!code||!email||!email_code||!username||!password){err.textContent='请填写所有字段';return;} if(password!==confirm){err.textContent='两次密码不一致';return;} const btn=document.getElementById('regBtn'); btn.disabled=true; try{ const csrftoken=getCookie('csrftoken'); - const resp=await fetch('/accounts/register/submit/',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json','X-CSRFToken':csrftoken||''},body:JSON.stringify({code,email,username,password})}); + const resp=await fetch('/accounts/register/submit/',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json','X-CSRFToken':csrftoken||''},body:JSON.stringify({code,email,email_code,username,password})}); const data=await resp.json(); if(!resp.ok||!data.ok){throw new Error(data.message||'注册失败');} window.location.href=data.redirect_url; }catch(e){err.textContent=e.message||'发生错误';} finally{btn.disabled=false;} }); + document.getElementById('sendCodeBtn').addEventListener('click',async()=>{ + const email=(document.getElementById('email').value||'').trim(); + const msg=document.getElementById('sendMsg'); + msg.textContent=''; + if(!email){msg.textContent='请输入邮箱';return;} + const btn=document.getElementById('sendCodeBtn'); btn.disabled=true; + try{ + const csrftoken=getCookie('csrftoken'); + const resp=await fetch('/accounts/email/send-code/',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json','X-CSRFToken':csrftoken||''},body:JSON.stringify({email})}); + const data=await resp.json(); + if(!resp.ok||!data.ok){throw new Error(data.message||'发送失败');} + msg.textContent='验证码已发送,请查收邮件'; + }catch(e){msg.textContent=e.message||'发送失败';} + finally{btn.disabled=false;} + });