From ebacfd43be5e292248a5e175afc56aac7e08c17c Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Wed, 21 Jun 2023 20:00:48 +0100 Subject: [PATCH] form: fix captcha, matrix, telegram new issue though: discord/telegram/matrix aren't linked when email confirmation is used! --- api-users.go | 4 +-- html/create-success.html | 2 +- router.go | 2 +- ts/form.ts | 63 +++++++++++++++-------------------- ts/modules/account-linking.ts | 4 +-- 5 files changed, 33 insertions(+), 42 deletions(-) diff --git a/api-users.go b/api-users.go index 94d5b59..4a54e01 100644 --- a/api-users.go +++ b/api-users.go @@ -121,7 +121,7 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc return } } else { - discordUser, discordVerified = app.discord.verifiedTokens[req.DiscordPIN] + discordUser, discordVerified = app.discord.UserVerified(req.DiscordPIN) if !discordVerified { f = func(gc *gin.Context) { app.debug.Printf("%s: New user failed: Discord PIN was invalid", req.Code) @@ -207,7 +207,7 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc } } else { tgToken, telegramVerified = app.telegram.TokenVerified(req.TelegramPIN) - if telegramVerified { + if !telegramVerified { f = func(gc *gin.Context) { app.debug.Printf("%s: New user failed: Telegram PIN was invalid", req.Code) respond(401, "errorInvalidPIN", gc) diff --git a/html/create-success.html b/html/create-success.html index 4988e8e..c4e87d7 100644 --- a/html/create-success.html +++ b/html/create-success.html @@ -1,7 +1,7 @@ - + {{ template "header.html" . }} {{ .strings.successHeader }} - jfa-go diff --git a/router.go b/router.go index 72faa01..f0fd890 100644 --- a/router.go +++ b/router.go @@ -236,7 +236,7 @@ func (app *appContext) loadRoutes(router *gin.Engine) { user.GET(p+"/discord/verified/:pin", app.MyDiscordVerifiedInvite) user.GET(p+"/telegram/verified/:pin", app.MyTelegramVerifiedInvite) user.POST(p+"/matrix/user", app.MatrixSendMyPIN) - user.POST(p+"/matrix/verified/:userID/:pin", app.MatrixCheckMyPIN) + user.GET(p+"/matrix/verified/:userID/:pin", app.MatrixCheckMyPIN) user.DELETE(p+"/discord", app.UnlinkMyDiscord) user.DELETE(p+"/telegram", app.UnlinkMyTelegram) user.DELETE(p+"/matrix", app.UnlinkMyMatrix) diff --git a/ts/form.ts b/ts/form.ts index 961de8a..428f19f 100644 --- a/ts/form.ts +++ b/ts/form.ts @@ -176,33 +176,31 @@ let captchaInput = document.getElementById("captcha-input") as HTMLInputElement; const captchaCheckbox = document.getElementById("captcha-success") as HTMLSpanElement; let prevCaptcha = ""; -function baseValidator(oncomplete: (valid: boolean) => void): void { - let captchaChecked = false; - let captchaChange = false; - if (window.captcha && !window.reCAPTCHA) { - captchaChange = captchaInput.value != prevCaptcha; - if (captchaChange) { - prevCaptcha = captchaInput.value; - _post("/captcha/verify/" + window.code + "/" + captchaID + "/" + captchaInput.value, null, (req: XMLHttpRequest) => { - if (req.readyState == 4) { - if (req.status == 204) { - captchaCheckbox.innerHTML = ``; - captchaCheckbox.classList.add("~positive"); - captchaCheckbox.classList.remove("~critical"); - captchaVerified = true; - captchaChecked = true; - } else { - captchaCheckbox.innerHTML = ``; - captchaCheckbox.classList.add("~critical"); - captchaCheckbox.classList.remove("~positive"); - captchaVerified = false; - captchaChecked = true; - return; - } +let baseValidator = (oncomplete: (valid: boolean) => void): void => { + if (window.captcha && !window.reCAPTCHA && (captchaInput.value != prevCaptcha)) { + prevCaptcha = captchaInput.value; + _post("/captcha/verify/" + window.code + "/" + captchaID + "/" + captchaInput.value, null, (req: XMLHttpRequest) => { + if (req.readyState == 4) { + if (req.status == 204) { + captchaCheckbox.innerHTML = ``; + captchaCheckbox.classList.add("~positive"); + captchaCheckbox.classList.remove("~critical"); + captchaVerified = true; + } else { + captchaCheckbox.innerHTML = ``; + captchaCheckbox.classList.add("~critical"); + captchaCheckbox.classList.remove("~positive"); + captchaVerified = false; } - }); - } + _baseValidator(oncomplete, captchaVerified); + } + }); + } else { + _baseValidator(oncomplete, captchaVerified); } +} + +function _baseValidator(oncomplete: (valid: boolean) => void, captchaValid: boolean): void { if (window.emailRequired) { if (!emailField.value.includes("@")) { oncomplete(false); @@ -221,18 +219,11 @@ function baseValidator(oncomplete: (valid: boolean) => void): void { oncomplete(false); return; } - if (window.captcha && !window.reCAPTCHA) { - if (!captchaChange) { - oncomplete(captchaVerified); - return; - } - while (!captchaChecked) { - continue; - } - oncomplete(captchaVerified); - } else { - oncomplete(true); + if (window.captcha && !window.reCAPTCHA && !captchaValid) { + oncomplete(false); + return; } + oncomplete(true); } interface GreCAPTCHA { diff --git a/ts/modules/account-linking.ts b/ts/modules/account-linking.ts index 45b1311..bdc92be 100644 --- a/ts/modules/account-linking.ts +++ b/ts/modules/account-linking.ts @@ -243,7 +243,7 @@ export class Matrix { this._input.value = ""; }); - private _verifyCode = () => _post(this._conf.verifiedURL + this._userID + "/" + this._input.value, null, (req: XMLHttpRequest) => { + private _verifyCode = () => _get(this._conf.verifiedURL + this._userID + "/" + this._input.value, null, (req: XMLHttpRequest) => { if (req.readyState != 4) return; removeLoader(this._submit); const valid = req.response["success"] as boolean; @@ -264,6 +264,6 @@ export class Matrix { this._submit.classList.remove("~critical"); }, 800); } - }, true); + }); }