From 0782011f54dca98d96a8c5a78f68569ed045892a Mon Sep 17 00:00:00 2001 From: "X. Ding" Date: Fri, 28 Oct 2022 18:25:01 +0800 Subject: Add hcaptcha support besides Google ReCaptcha (#2834) ### Pull Request Checklist This PR add support for hcaptcha.com as an alternative to Google ReCaptcha. It also makes possible for user to customize ReCaptcha URL when needed. (Such as use recaptcha.net instead of www.google.com) This feature needs manual test cuz it involves 3rd party _captcha_. Signed-off-by: `Simon Ding ` Co-authored-by: dxl --- setup/config/config_clientapi.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'setup') diff --git a/setup/config/config_clientapi.go b/setup/config/config_clientapi.go index 56f4b3f9..0a871da1 100644 --- a/setup/config/config_clientapi.go +++ b/setup/config/config_clientapi.go @@ -32,6 +32,12 @@ type ClientAPI struct { // Boolean stating whether catpcha registration is enabled // and required RecaptchaEnabled bool `yaml:"enable_registration_captcha"` + // Recaptcha api.js Url, for compatible with hcaptcha.com, etc. + RecaptchaApiJsUrl string `yaml:"recaptcha_api_js_url"` + // Recaptcha div class for sitekey, for compatible with hcaptcha.com, etc. + RecaptchaSitekeyClass string `yaml:"recaptcha_sitekey_class"` + // Recaptcha form field, for compatible with hcaptcha.com, etc. + RecaptchaFormField string `yaml:"recaptcha_form_field"` // This Home Server's ReCAPTCHA public key. RecaptchaPublicKey string `yaml:"recaptcha_public_key"` // This Home Server's ReCAPTCHA private key. @@ -75,6 +81,18 @@ func (c *ClientAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { checkNotEmpty(configErrs, "client_api.recaptcha_public_key", c.RecaptchaPublicKey) checkNotEmpty(configErrs, "client_api.recaptcha_private_key", c.RecaptchaPrivateKey) checkNotEmpty(configErrs, "client_api.recaptcha_siteverify_api", c.RecaptchaSiteVerifyAPI) + if c.RecaptchaSiteVerifyAPI == "" { + c.RecaptchaSiteVerifyAPI = "https://www.google.com/recaptcha/api/siteverify" + } + if c.RecaptchaApiJsUrl == "" { + c.RecaptchaApiJsUrl = "https://www.google.com/recaptcha/api.js" + } + if c.RecaptchaFormField == "" { + c.RecaptchaFormField = "g-recaptcha" + } + if c.RecaptchaSitekeyClass == "" { + c.RecaptchaSitekeyClass = "g-recaptcha-response" + } } // Ensure there is any spam counter measure when enabling registration if !c.RegistrationDisabled && !c.OpenRegistrationWithoutVerificationEnabled { -- cgit v1.2.3