From 7c67d8c57ce9906e93bd228e5d00326efb6cb448 Mon Sep 17 00:00:00 2001 From: Elijah R Date: Mon, 6 Jan 2025 23:09:04 -0500 Subject: [PATCH] thanks --- src/ts/AuthManager.ts | 20 ++++++++++---------- src/ts/main.ts | 42 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/ts/AuthManager.ts b/src/ts/AuthManager.ts index 94a9a07..aff91cc 100644 --- a/src/ts/AuthManager.ts +++ b/src/ts/AuthManager.ts @@ -21,9 +21,9 @@ export default class AuthManager { login(username : string, password : string, captchaToken : string | undefined, turnstileToken : string | undefined, recaptchaToken : string | undefined) : Promise { return new Promise(async (res,rej) => { if (!this.info) throw new Error("Cannot login before fetching API information."); - if (!captchaToken && this.info.hcaptcha.required) throw new Error("This API requires a valid hCaptcha token."); - if (!turnstileToken && this.info.turnstile.required) throw new Error("This API requires a valid Turnstile token."); - if (!recaptchaToken && this.info.recaptcha.required) throw new Error("This API requires a valid reCAPTCHA token."); + if (!captchaToken && this.info.hcaptcha?.required) throw new Error("This API requires a valid hCaptcha token."); + if (!turnstileToken && this.info.turnstile?.required) throw new Error("This API requires a valid Turnstile token."); + if (!recaptchaToken && this.info.recaptcha?.required) throw new Error("This API requires a valid reCAPTCHA token."); var data = await fetch(this.apiEndpoint + "/api/v1/login", { method: "POST", headers: { @@ -76,9 +76,9 @@ export default class AuthManager { register(username : string, password : string, email : string, dateOfBirth : dayjs.Dayjs, captchaToken : string | undefined, turnstileToken: string | undefined, recaptchaToken : string | undefined) : Promise { return new Promise(async (res, rej) => { if (!this.info) throw new Error("Cannot login before fetching API information."); - if (!captchaToken && this.info.hcaptcha.required) throw new Error("This API requires a valid hCaptcha token."); - if (!turnstileToken && this.info.turnstile.required) throw new Error("This API requires a valid Turnstile token."); - if (!recaptchaToken && this.info.recaptcha.required) throw new Error("This API requires a valid reCAPTCHA token."); + if (!captchaToken && this.info.hcaptcha?.required) throw new Error("This API requires a valid hCaptcha token."); + if (!turnstileToken && this.info.turnstile?.required) throw new Error("This API requires a valid Turnstile token."); + if (!recaptchaToken && this.info.recaptcha?.required) throw new Error("This API requires a valid reCAPTCHA token."); var data = await fetch(this.apiEndpoint + "/api/v1/register", { method: "POST", headers: { @@ -165,9 +165,9 @@ export default class AuthManager { sendPasswordResetEmail(username : string, email : string, captchaToken : string | undefined, turnstileToken : string | undefined, recaptchaToken : string | undefined) { return new Promise(async res => { if (!this.info) throw new Error("Cannot send password reset email without fetching API information."); - if (!captchaToken && this.info.hcaptcha.required) throw new Error("This API requires a valid hCaptcha token."); - if (!turnstileToken && this.info.turnstile.required) throw new Error("This API requires a valid Turnstile token."); - if (!recaptchaToken && this.info.recaptcha.required) throw new Error("This API requires a valid reCAPTCHA token."); + if (!captchaToken && this.info.hcaptcha?.required) throw new Error("This API requires a valid hCaptcha token."); + if (!turnstileToken && this.info.turnstile?.required) throw new Error("This API requires a valid Turnstile token."); + if (!recaptchaToken && this.info.recaptcha?.required) throw new Error("This API requires a valid reCAPTCHA token."); var data = await fetch(this.apiEndpoint + "/api/v1/sendreset", { method: "POST", headers: { @@ -273,4 +273,4 @@ export interface UpdateAccountResult { export interface PasswordResetResult { success : boolean; error : string | undefined; -} \ No newline at end of file +} diff --git a/src/ts/main.ts b/src/ts/main.ts index 3eec07b..6930ad7 100644 --- a/src/ts/main.ts +++ b/src/ts/main.ts @@ -964,7 +964,7 @@ async function renderAuth() { element.remove(); } - if (auth!.info!.hcaptcha.required) { + if (auth!.info!.hcaptcha?.required) { const hconfig = { sitekey: auth!.info!.hcaptcha.siteKey! }; let renderHcaptcha = () => { @@ -1001,7 +1001,7 @@ async function renderAuth() { } } - if (auth!.info?.turnstile.required) { + if (auth!.info?.turnstile?.required) { const turnstileConfig = { sitekey: auth!.info!.turnstile.siteKey! }; let renderTurnstile = () => { @@ -1038,7 +1038,7 @@ async function renderAuth() { } } - if (auth!.info?.recaptcha.required) { + if (auth!.info?.recaptcha?.required) { const recaptchaConfig = { sitekey: auth!.info!.recaptcha.siteKey! }; let renderRecaptcha = () => { @@ -1148,7 +1148,7 @@ elements.accountLoginForm.addEventListener('submit', async (e) => { e.preventDefault(); var hcaptchaToken = undefined; var hcaptchaID = undefined; - if (auth!.info!.hcaptcha.required) { + if (auth!.info!.hcaptcha?.required) { hcaptchaID = elements.accountLoginCaptchaContainer.getAttribute("data-hcaptcha-widget-id")! var response = hcaptcha.getResponse(hcaptchaID); if (response === "") { @@ -1162,7 +1162,7 @@ elements.accountLoginForm.addEventListener('submit', async (e) => { var turnstileToken = undefined; var turnstileID = undefined; - if (auth!.info!.turnstile.required) { + if (auth!.info!.turnstile?.required) { turnstileID = elements.accountLoginTurnstileContainer.getAttribute("data-turnstile-widget-id")! var response: string = turnstile.getResponse(turnstileID) || ""; if (response === "") { @@ -1176,7 +1176,7 @@ elements.accountLoginForm.addEventListener('submit', async (e) => { var recaptchaToken = undefined; var recaptchaID = undefined; - if (auth!.info!.recaptcha.required) { + if (auth!.info!.recaptcha?.required) { recaptchaID = parseInt(elements.accountLoginRecaptchaContainer.getAttribute("data-recaptcha-widget-id")!) var response = grecaptcha.getResponse(recaptchaID); if (response === "") { @@ -1190,9 +1190,9 @@ elements.accountLoginForm.addEventListener('submit', async (e) => { var username = elements.accountLoginUsername.value; var password = elements.accountLoginPassword.value; var result = await auth!.login(username, password, hcaptchaToken, turnstileToken, recaptchaToken); - if (auth!.info!.hcaptcha.required) hcaptcha.reset(hcaptchaID); - if (auth!.info!.turnstile.required) turnstile.reset(turnstileID); - if (auth!.info!.recaptcha.required) grecaptcha.reset(recaptchaID); + if (auth!.info!.hcaptcha?.required) hcaptcha.reset(hcaptchaID); + if (auth!.info!.turnstile?.required) turnstile.reset(turnstileID); + if (auth!.info!.recaptcha?.required) grecaptcha.reset(recaptchaID); if (result.success) { elements.accountLoginUsername.value = ""; elements.accountLoginPassword.value = ""; @@ -1216,7 +1216,7 @@ elements.accountRegisterForm.addEventListener('submit', async (e) => { e.preventDefault(); var hcaptchaToken = undefined; var hcaptchaID = undefined; - if (auth!.info!.hcaptcha.required) { + if (auth!.info!.hcaptcha?.required) { hcaptchaID = elements.accountRegisterCaptchaContainer.getAttribute("data-hcaptcha-widget-id")! var response = hcaptcha.getResponse(hcaptchaID); if (response === "") { @@ -1230,7 +1230,7 @@ elements.accountRegisterForm.addEventListener('submit', async (e) => { var turnstileToken = undefined; var turnstileID = undefined; - if (auth!.info!.turnstile.required) { + if (auth!.info!.turnstile?.required) { turnstileID = elements.accountRegisterTurnstileContainer.getAttribute("data-turnstile-widget-id")! var response: string = turnstile.getResponse(turnstileID) || ""; if (response === "") { @@ -1244,7 +1244,7 @@ elements.accountRegisterForm.addEventListener('submit', async (e) => { var recaptchaToken = undefined; var recaptchaID = undefined; - if (auth!.info!.recaptcha.required) { + if (auth!.info!.recaptcha?.required) { recaptchaID = parseInt(elements.accountRegisterRecaptchaContainer.getAttribute("data-recaptcha-widget-id")!) var response = grecaptcha.getResponse(recaptchaID); if (response === "") { @@ -1265,9 +1265,9 @@ elements.accountRegisterForm.addEventListener('submit', async (e) => { return false; } var result = await auth!.register(username, password, email, dob, hcaptchaToken, turnstileToken, recaptchaToken); - if (auth!.info!.hcaptcha.required) hcaptcha.reset(hcaptchaID); - if (auth!.info!.turnstile.required) turnstile.reset(turnstileID); - if (auth!.info!.recaptcha.required) grecaptcha.reset(recaptchaID); + if (auth!.info!.hcaptcha?.required) hcaptcha.reset(hcaptchaID); + if (auth!.info!.turnstile?.required) turnstile.reset(turnstileID); + if (auth!.info!.recaptcha?.required) grecaptcha.reset(recaptchaID); if (result.success) { elements.accountRegisterUsername.value = ""; elements.accountRegisterEmail.value = ""; @@ -1360,7 +1360,7 @@ elements.accountResetPasswordForm.addEventListener('submit', async e => { e.preventDefault(); var hcaptchaToken = undefined; var hcaptchaID = undefined; - if (auth!.info!.hcaptcha.required) { + if (auth!.info!.hcaptcha?.required) { hcaptchaID = elements.accountResetPasswordCaptchaContainer.getAttribute("data-hcaptcha-widget-id")! var response = hcaptcha.getResponse(hcaptchaID); if (response === "") { @@ -1374,7 +1374,7 @@ elements.accountResetPasswordForm.addEventListener('submit', async e => { var turnstileToken = undefined; var turnstileID = undefined; - if (auth!.info!.turnstile.required) { + if (auth!.info!.turnstile?.required) { turnstileID = elements.accountResetPasswordTurnstileContainer.getAttribute("data-turnstile-widget-id")! var response: string = turnstile.getResponse(turnstileID) || ""; if (response === "") { @@ -1388,7 +1388,7 @@ elements.accountResetPasswordForm.addEventListener('submit', async e => { var recaptchaToken = undefined; var recaptchaID = undefined; - if (auth!.info!.recaptcha.required) { + if (auth!.info!.recaptcha?.required) { recaptchaID = parseInt(elements.accountResetPasswordRecaptchaContainer.getAttribute("data-recaptcha-widget-id")!) var response = grecaptcha.getResponse(recaptchaID); if (response === "") { @@ -1402,9 +1402,9 @@ elements.accountResetPasswordForm.addEventListener('submit', async e => { var username = elements.accountResetPasswordUsername.value; var email = elements.accountResetPasswordEmail.value; var result = await auth!.sendPasswordResetEmail(username, email, hcaptchaToken, turnstileToken, recaptchaToken); - if (auth!.info!.hcaptcha.required) hcaptcha.reset(hcaptchaID); - if (auth!.info!.turnstile.required) turnstile.reset(turnstileID); - if (auth!.info!.recaptcha.required) grecaptcha.reset(recaptchaID); + if (auth!.info!.hcaptcha?.required) hcaptcha.reset(hcaptchaID); + if (auth!.info!.turnstile?.required) turnstile.reset(turnstileID); + if (auth!.info!.recaptcha?.required) grecaptcha.reset(recaptchaID); if (result.success) { resetPasswordUsername = username; resetPasswordEmail = email;