mirror of
https://github.com/spchcap/speech.capital.git
synced 2026-01-14 08:38:42 +00:00
Fix: Reset Turnstile CAPTCHA on failed login
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
<p class="text-xs mt-4">No account? <a href="/signup" class="text-yellow-200/80 hover:text-yellow-200">Sign up</a>.</p>
|
<p class="text-xs mt-4">No account? <a href="/signup" class="text-yellow-200/80 hover:text-yellow-200">Sign up</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
f=()=>({u:'',p:'',e:null,l:false,async s(){this.l=!0;this.e=null;try{const token=this.$el.querySelector('[name="cf-turnstile-response"]')?.value;if(!token)throw new Error('Please complete the CAPTCHA.');const r1=await fetch(`/api/auth-params?username=${this.u}`);if(!r1.ok)throw new Error('User not found.');const{N,r,p,salt_b64}=await r1.json();const pw=(new TextEncoder()).encode(this.p),dec=s=>Uint8Array.from(atob(s),c=>c.charCodeAt(0)),salt=dec(salt_b64);const h=await scrypt.scrypt(pw,salt,N,r,p,32),b64=a=>btoa(String.fromCharCode(...a));const h_str=`scrypt$${N}$${r}$${p}$${salt_b64}$${b64(h)}`;const r2=await fetch('/api/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:this.u,pass_hash:h_str,'cf-turnstile-response':token})});if(!r2.ok){const d=await r2.json();throw new Error(d.error?.message||'Login failed')}window.location.href='/'}catch(e){this.e=e.message}finally{this.l=!1}}})
|
f=()=>({u:'',p:'',e:null,l:false,async s(){this.l=!0;this.e=null;try{const token=this.$el.querySelector('[name="cf-turnstile-response"]')?.value;if(!token)throw new Error('Please complete the CAPTCHA.');const r1=await fetch(`/api/auth-params?username=${this.u}`);if(!r1.ok)throw new Error('User not found.');const{N,r,p,salt_b64}=await r1.json();const pw=(new TextEncoder()).encode(this.p),dec=s=>Uint8Array.from(atob(s),c=>c.charCodeAt(0)),salt=dec(salt_b64);const h=await scrypt.scrypt(pw,salt,N,r,p,32),b64=a=>btoa(String.fromCharCode(...a));const h_str=`scrypt$${N}$${r}$${p}$${salt_b64}$${b64(h)}`;const r2=await fetch('/api/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:this.u,pass_hash:h_str,'cf-turnstile-response':token})});if(!r2.ok){const d=await r2.json();throw new Error(d.error?.message||'Login failed')}window.location.href='/'}catch(e){this.e=e.message;turnstile.reset(this.$el.querySelector('.cf-turnstile'))}finally{this.l=!1}}})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user