From 0606f057071ef31084988397b7c8aa3d28b6d780 Mon Sep 17 00:00:00 2001 From: Leni Kadali Date: Tue, 26 Aug 2025 20:30:18 +0200 Subject: [PATCH] chore: Use common SetCaptchaData in link account (#8592) Fixes [#7990](https://codeberg.org/forgejo/forgejo/issues/7990) This PR upstreams commit [2bf3621c99](https://codeberg.org/Codeberg-Infrastructure/forgejo/commit/2bf3621c99f04112015ecbdc2106744a2370844c) which fixes `SetCaptcha` not being called when it is typically used in other places. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8592 Reviewed-by: Beowulf Co-authored-by: Leni Kadali Co-committed-by: Leni Kadali --- routers/web/auth/linkaccount.go | 36 +++++++++------------------------ 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go index 2bba614d8c..031998d3a1 100644 --- a/routers/web/auth/linkaccount.go +++ b/routers/web/auth/linkaccount.go @@ -32,15 +32,9 @@ func LinkAccount(ctx *context.Context) { ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration ctx.Data["Title"] = ctx.Tr("link_account") ctx.Data["LinkAccountMode"] = true - ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha - ctx.Data["Captcha"] = context.GetImageCaptcha() - ctx.Data["CaptchaType"] = setting.Service.CaptchaType - ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL - ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey - ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey - ctx.Data["McaptchaSitekey"] = setting.Service.McaptchaSitekey - ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL - ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey + if setting.Service.RequireExternalRegistrationCaptcha { + context.SetCaptchaData(ctx) + } ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration ctx.Data["AllowOnlyInternalRegistration"] = setting.Service.AllowOnlyInternalRegistration ctx.Data["ShowRegistrationButton"] = false @@ -112,15 +106,9 @@ func LinkAccountPostSignIn(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("link_account") ctx.Data["LinkAccountMode"] = true ctx.Data["LinkAccountModeSignIn"] = true - ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha - ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL - ctx.Data["Captcha"] = context.GetImageCaptcha() - ctx.Data["CaptchaType"] = setting.Service.CaptchaType - ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey - ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey - ctx.Data["McaptchaSitekey"] = setting.Service.McaptchaSitekey - ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL - ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey + if setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha { + context.SetCaptchaData(ctx) + } ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration ctx.Data["ShowRegistrationButton"] = false ctx.Data["EnableInternalSignIn"] = true @@ -200,15 +188,9 @@ func LinkAccountPostRegister(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("link_account") ctx.Data["LinkAccountMode"] = true ctx.Data["LinkAccountModeRegister"] = true - ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha - ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL - ctx.Data["Captcha"] = context.GetImageCaptcha() - ctx.Data["CaptchaType"] = setting.Service.CaptchaType - ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey - ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey - ctx.Data["McaptchaSitekey"] = setting.Service.McaptchaSitekey - ctx.Data["McaptchaURL"] = setting.Service.McaptchaURL - ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey + if setting.Service.RequireExternalRegistrationCaptcha { + context.SetCaptchaData(ctx) + } ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration ctx.Data["ShowRegistrationButton"] = false