fixed captcha more and better errors

This commit is contained in:
MathMan05 2024-07-28 16:07:21 -05:00
parent 3621f1b09b
commit f10ea4ac2a
7 changed files with 197 additions and 52 deletions

View file

@ -16,7 +16,7 @@ async function registertry(e){
const dateofbirth=elements[5].value;
const apiurl=new URL(JSON.parse(localStorage.getItem("instanceinfo")).api)
fetch(apiurl+"/auth/register",{
await fetch(apiurl+"/auth/register",{
body:JSON.stringify({
date_of_birth:dateofbirth,
email:email,
@ -33,19 +33,35 @@ async function registertry(e){
e.json().then(e=>{
if(e.captcha_sitekey){
const capt=document.getElementById("h-captcha");
const capty=document.createElement("div");
capty.classList.add("h-captcha");
if(!capt.children.length){
const capty=document.createElement("div");
capty.classList.add("h-captcha");
capty.setAttribute("data-sitekey", e.captcha_sitekey);
const script=document.createElement("script");
script.src="https://js.hcaptcha.com/1/api.js";
capt.append(script);
capt.append(capty);
capty.setAttribute("data-sitekey", e.captcha_sitekey);
const script=document.createElement("script");
script.src="https://js.hcaptcha.com/1/api.js";
capt.append(script);
capt.append(capty);
}else{
eval("hcaptcha.reset()");
}
return;
}
if(!e.token){
console.log(e);
document.getElementById("wrong").textContent=e.errors[Object.keys(e.errors)[0]]._errors[0].message;
if(e.errors.consent){
error(elements[6],e.errors.consent._errors[0].message);
}else if(e.errors.password){
error(elements[3],e.errors.password._errors[0].message);
}else if(e.errors.username){
error(elements[2],e.errors.username._errors[0].message);
}else if(e.errors.email){
error(elements[1],e.errors.email._errors[0].message);
}else if(e.errors.date_of_birth){
error(elements[5],e.errors.date_of_birth._errors[0].message);
}else{
document.getElementById("wrong").textContent=e.errors[Object.keys(e.errors)[0]]._errors[0].message;
}
}else{
localStorage.setItem("token",e.token);
window.location.href = '/channels/@me';
@ -55,6 +71,20 @@ async function registertry(e){
//document.getElementById("wrong").textContent=h;
// console.log(h);
}
function error(e:HTMLFormElement,message:string){
const p=e.parentElement;
let element=p.getElementsByClassName("suberror")[0] as HTMLElement;
if(!element){
const div=document.createElement("div");
div.classList.add("suberror","suberrora");
p.append(div);
element=div;
}else{
element.classList.remove("suberror");
setTimeout(_=>{element.classList.add("suberror")},100);
}
element.textContent=message;
}
let TOSa=document.getElementById("TOSa");
async function tosLogic(){
const apiurl=new URL(JSON.parse(localStorage.getItem("instanceinfo")).api)