let toofastman=true;setTimeout((function(){toofastman=false}),1e3);let googleUser={};let startApp=function(){utilGlobal.sessionAuthFunc=sessionAuth;gapi.load("auth2",(function(){auth2=gapi.auth2.init({client_id:"867451001319-ptvsiql62en4l3vvklhgnv02nm6bi7ge.apps.googleusercontent.com",cookiepolicy:"https://www."+window.location.host});attachSignin(document.getElementById("customBtn"))}))};function attachSignin(element){auth2.attachClickHandler(element,{},(function onSignIn(googleUser){let profile=googleUser.getBasicProfile();if(toofastman){gapi.auth2.getAuthInstance().signOut();return}let response={authwith:"google",token:googleUser.getAuthResponse().id_token};const option={endpoint:"/api/login",request:{method:"POST",headers:{"X-Website":Website},body:JSON.stringify(response)}};fetch(option.endpoint,option.request).then((response=>{if(response.status===200){}else if(response.status===531){Swal.fire("Our connection with Google failed")}else if(response.status===808){Swal.fire("We could not find an account under your email.")}else if(response.status===809){Swal.fire("We could not find your linked Google account.")}else{Swal.fire("Unexpected API response. Please contact us.")}return response.json()})).then((data=>{if(data)utilGlobal.data=data;if(data.uid){uid=data.uid;utilGlobal.uid=data.uid}if(data.otp){utilGlobal.finalCall=sessionAuth;utilGlobal.OTP()}else{if(data.token)token=data.token;utilGlobal.sessionAuthFunc(uid,token)}})).catch((error=>console.error(error)))}),(function(error){alert(JSON.stringify(error,undefined,2))}))}function validateEmail(email){const re=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return re.test(email)}function auth(){let data={};data.email=document.getElementById("email").value.trim();data.password=document.getElementById("password").value.trim();email=data.email;if(!validateEmail(email)){Swal.fire("Please use your email to login!");return}if(!data.password){ShowError("Please input your password!");return}const option={endpoint:"/api/login",request:{method:"POST",headers:{"X-Website":Website},body:JSON.stringify(data)}};fetch(option.endpoint,option.request).then((response=>{if(response.status===200){return response.json()}else if(response.status===401){Swal.fire("Sorry, the password is wrong.")}else if(response.status===808){Swal.fire("We couldn't find your account. Please try again.")}else{Swal.fire("Unexpected API response. Please contact us.")}return response.json()})).then((data=>{if(data)utilGlobal.data=data;if(data.uid){uid=data.uid;utilGlobal.uid=data.uid}if(data.otp){utilGlobal.finalCall=sessionAuth;utilGlobal.OTP()}else{if(data.token)token=data.token;utilGlobal.sessionAuthFunc(uid,token)}})).catch((error=>console.error(error)))}function sessionAuth(uid,token){const request={endpoint:"/order-auth.php",request:{method:"POST",body:new URLSearchParams({uid:uid,token:token})}};fetch(request.endpoint,request.request).then((function(response){if(response.status===200){localStorage.setItem("token",token);window.location.href="/new-control-panel/"}})).catch((error=>console.error(error)))}function resetPassword(){let email;email=document.getElementById("email").value.trim();if(!validateEmail(email)){Swal.fire("Please use your email to login!");return}const options={endpoint:"/api/forgotpassword/"+email+"/"+Website};fetch(options.endpoint,options.request).then((response=>{if(response.status===200){setTimeout((function(){Swal.fire("Email Sent","Check your email for the code!","success")}),3e3);if(Website==="primcast.com"){window.location.href="/reset-password/verification/"}else{window.location.href="/reset-password/?step=code"}}else if(response.status===604){Swal.fire("Your email doesn't seem to exist in our database?")}else{Swal.fire("Unexpected API response. Please contact us.")}})).catch((error=>{console.log(error)}))}function sendResetRequest(){let data={},cpassword;data.id=document.getElementById("code").value.trim();data.newpassword=document.getElementById("password").value.trim();cpassword=document.getElementById("new-password").value.trim();if(data.newpassword!==cpassword)Swal.fire("Passwords must match");else if(cpassword.length<6)Swal.fire("Minimum password length is 6 chars");else{const options={endpoint:"/api/resetpassword/"+Website,request:{method:"POST",body:JSON.stringify(data)}};fetch(options.endpoint,options.request).then((response=>{if(response.status===200){Swal.fire("Status","Password successfully changed","success");window.location.href="/login"}else if(response.status===604){Swal.fire("The code is not valid")}else{Swal.fire("Unexpected API response. Please contact us.")}})).catch((error=>{console.log(error)}))}}