diff --git a/crates/cli/src/util.rs b/crates/cli/src/util.rs index ba3e3d7a..02520fc4 100644 --- a/crates/cli/src/util.rs +++ b/crates/cli/src/util.rs @@ -129,6 +129,9 @@ pub fn captcha_config_from_config( let service = match service { mas_config::CaptchaServiceKind::RecaptchaV2 => mas_data_model::CaptchaService::RecaptchaV2, + mas_config::CaptchaServiceKind::CloudflareTurnstile => { + mas_data_model::CaptchaService::CloudflareTurnstile + } }; Ok(Some(mas_data_model::CaptchaConfig { diff --git a/crates/config/src/sections/captcha.rs b/crates/config/src/sections/captcha.rs index 00badc69..4a732ff5 100644 --- a/crates/config/src/sections/captcha.rs +++ b/crates/config/src/sections/captcha.rs @@ -23,6 +23,10 @@ pub enum CaptchaServiceKind { /// Use Google's reCAPTCHA v2 API #[serde(rename = "recaptcha_v2")] RecaptchaV2, + + /// Use Cloudflare Turnstile + #[serde(rename = "cloudflare_turnstile")] + CloudflareTurnstile, } /// Configuration section to setup CAPTCHA protection on a few operations diff --git a/crates/data-model/src/site_config.rs b/crates/data-model/src/site_config.rs index e33dc89e..68ed5aea 100644 --- a/crates/data-model/src/site_config.rs +++ b/crates/data-model/src/site_config.rs @@ -19,6 +19,7 @@ use url::Url; #[derive(Debug, Clone)] pub enum CaptchaService { RecaptchaV2, + CloudflareTurnstile, } /// Captcha configuration diff --git a/crates/templates/src/context/captcha.rs b/crates/templates/src/context/captcha.rs index 23416a2f..95dec4f6 100644 --- a/crates/templates/src/context/captcha.rs +++ b/crates/templates/src/context/captcha.rs @@ -30,6 +30,9 @@ impl Object for CaptchaConfig { match key.as_str() { Some("service") => Some(match &self.0.service { mas_data_model::CaptchaService::RecaptchaV2 => "recaptcha_v2".into(), + mas_data_model::CaptchaService::CloudflareTurnstile => { + "cloudflare_turnstile".into() + } }), Some("site_key") => Some(self.0.site_key.clone().into()), _ => None, diff --git a/docs/config.schema.json b/docs/config.schema.json index 5faa9dc4..73fbdf73 100644 --- a/docs/config.schema.json +++ b/docs/config.schema.json @@ -1988,6 +1988,13 @@ "enum": [ "recaptcha_v2" ] + }, + { + "description": "Use Cloudflare Turnstile", + "type": "string", + "enum": [ + "cloudflare_turnstile" + ] } ] }, diff --git a/templates/components/captcha.html b/templates/components/captcha.html index 5fbd139e..d2ba474e 100644 --- a/templates/components/captcha.html +++ b/templates/components/captcha.html @@ -14,10 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. #} -{% macro form() -%} +{% macro form(class="") -%} {%- if captcha|default(False) -%} {%- if captcha.service == "recaptcha_v2" -%} -
+
+ {%- elif captcha.service == "cloudflare_turnstile" -%} +
{%- else -%} {{ throw(message="Invalid captcha service setup") }} {%- endif %} @@ -28,6 +30,8 @@ limitations under the License. {%- if captcha|default(False) -%} {%- if captcha.service == "recaptcha_v2" -%} + {%- elif captcha.service == "cloudflare_turnstile" -%} + {%- else -%} {{ throw(message="Invalid captcha service setup") }} {%- endif %} diff --git a/templates/pages/register.html b/templates/pages/register.html index aa47508f..1b4d9937 100644 --- a/templates/pages/register.html +++ b/templates/pages/register.html @@ -69,7 +69,7 @@ limitations under the License. {% endcall %} {% endif %} - {{ captcha.form() }} + {{ captcha.form(class="mb-4 self-center") }} {{ button.button(text=_("action.continue")) }}