Rename the WithCaptcha template context field to captcha_config

The field name is now more descriptive of what it actually is – the
configuration of the CAPTCHA provider – and aligns with the key used
when passing it to the client-side React form.
This commit is contained in:
Quentin Gliech
2026-07-30 20:50:59 +02:00
parent 7abe147ba0
commit a7f1d2d98d
2 changed files with 14 additions and 13 deletions
+3 -2
View File
@@ -1,3 +1,4 @@
// Copyright 2025, 2026 Element Creations Ltd.
// Copyright 2024, 2025 New Vector Ltd.
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
@@ -42,7 +43,7 @@ impl Object for CaptchaConfig {
/// Context with an optional CAPTCHA configuration in it
#[derive(Serialize)]
pub struct WithCaptcha<T> {
captcha: Option<Value>,
captcha_config: Option<Value>,
#[serde(flatten)]
inner: T,
@@ -52,7 +53,7 @@ impl<T> WithCaptcha<T> {
#[must_use]
pub(crate) fn new(captcha: Option<mas_data_model::CaptchaConfig>, inner: T) -> Self {
Self {
captcha: captcha.map(|captcha| Value::from_object(CaptchaConfig(captcha))),
captcha_config: captcha.map(|captcha| Value::from_object(CaptchaConfig(captcha))),
inner,
}
}
+11 -11
View File
@@ -7,19 +7,19 @@ Please see LICENSE files in the repository root for full details.
-#}
{% macro form(class="") -%}
{%- if captcha|default(False) -%}
{%- if captcha_config|default(False) -%}
<noscript>
<div class="captcha-noscript">
{{ _("mas.captcha.noscript") }}
</div>
</noscript>
{%- if captcha.service == "recaptcha_v2" -%}
<div class="g-recaptcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
{%- elif captcha.service == "cloudflare_turnstile" -%}
<div class="cf-turnstile {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
{%- elif captcha.service == "hcaptcha" -%}
<div class="h-captcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
{%- if captcha_config.service == "recaptcha_v2" -%}
<div class="g-recaptcha {{ class }}" data-sitekey="{{ captcha_config.site_key }}"></div>
{%- elif captcha_config.service == "cloudflare_turnstile" -%}
<div class="cf-turnstile {{ class }}" data-sitekey="{{ captcha_config.site_key }}"></div>
{%- elif captcha_config.service == "hcaptcha" -%}
<div class="h-captcha {{ class }}" data-sitekey="{{ captcha_config.site_key }}"></div>
{%- else -%}
{{ throw(message="Invalid captcha service setup") }}
{%- endif %}
@@ -27,12 +27,12 @@ Please see LICENSE files in the repository root for full details.
{% endmacro %}
{% macro head() -%}
{%- if captcha|default(False) -%}
{%- if captcha.service == "recaptcha_v2" -%}
{%- if captcha_config|default(False) -%}
{%- if captcha_config.service == "recaptcha_v2" -%}
<script src="https://www.recaptcha.net/recaptcha/api.js" async defer></script>
{%- elif captcha.service == "cloudflare_turnstile" -%}
{%- elif captcha_config.service == "cloudflare_turnstile" -%}
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
{%- elif captcha.service == "hcaptcha" -%}
{%- elif captcha_config.service == "hcaptcha" -%}
<script src="https://js.hcaptcha.com/1/api.js?recaptchacompat=off" async defer></script>
{%- else -%}
{{ throw(message="Invalid captcha service setup") }}