This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git

commit 9e629d2e562aabd7b63de6e455a29a8dd3b10aad
Author: lightumcc <[email protected]>
AuthorDate: Sat Jul 27 20:45:47 2024 +0800

    feat(recaptcha): Site Verify Endpoint Config
---
 captcha-google-v2/i18n/en_US.yaml     |  5 +++++
 captcha-google-v2/i18n/translation.go |  2 ++
 captcha-google-v2/i18n/zh_CN.yaml     |  5 +++++
 captcha-google-v2/recaptcha.go        | 18 +++++++++++++++++-
 4 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/captcha-google-v2/i18n/en_US.yaml 
b/captcha-google-v2/i18n/en_US.yaml
index 58b4174..f254632 100644
--- a/captcha-google-v2/i18n/en_US.yaml
+++ b/captcha-google-v2/i18n/en_US.yaml
@@ -34,6 +34,11 @@ plugin:
             other: Secret Key
           description:
             other: Get it from https://www.google.com/recaptcha/admin
+        site_verify_endpoint:
+          title:
+            other: Site Verify Endpoint
+          description:
+            other: If you can't access google.com, you can replace it with 
https://www.recaptcha.net/recaptcha/api/siteverify
     frontend:
       info:
         name:
diff --git a/captcha-google-v2/i18n/translation.go 
b/captcha-google-v2/i18n/translation.go
index b531c43..7a84a0c 100644
--- a/captcha-google-v2/i18n/translation.go
+++ b/captcha-google-v2/i18n/translation.go
@@ -26,4 +26,6 @@ const (
        ConfigSiteKeyDescription   = 
"plugin.google_v2_captcha.backend.config.site_key.description"
        ConfigSecretKeyTitle       = 
"plugin.google_v2_captcha.backend.config.secret_key.title"
        ConfigSecretKeyDescription = 
"plugin.google_v2_captcha.backend.config.secret_key.description"
+       ConfigSiteVerifyEndpointTitle = 
"plugin.google_v2_captcha.backend.config.site_verify_endpoint.title"
+       ConfigSiteVerifyEndpointDescription = 
"plugin.google_v2_captcha.backend.config.site_verify_endpoint.description"
 )
diff --git a/captcha-google-v2/i18n/zh_CN.yaml 
b/captcha-google-v2/i18n/zh_CN.yaml
index 58a9d53..08a9182 100644
--- a/captcha-google-v2/i18n/zh_CN.yaml
+++ b/captcha-google-v2/i18n/zh_CN.yaml
@@ -34,6 +34,11 @@ plugin:
             other: Secret Key
           description:
             other: 此密钥用于您的网站和 reCAPTCHA 之间的通信,从 
https://www.google.com/recaptcha/admin 获取
+        site_verify_endpoint:
+          title:
+            other: Site Verify API端点
+          description:
+            other: 如果您无法访问google.com, 可以将其替换为 
https://www.recaptcha.net/recaptcha/api/siteverify
     frontend:
       title: 验证码
       placeholder: 输入上面的文本
diff --git a/captcha-google-v2/recaptcha.go b/captcha-google-v2/recaptcha.go
index 127afe0..7083bdc 100644
--- a/captcha-google-v2/recaptcha.go
+++ b/captcha-google-v2/recaptcha.go
@@ -44,6 +44,7 @@ type Captcha struct {
 type CaptchaConfig struct {
        SiteKey   string `json:"site_key"`
        SecretKey string `json:"secret_key"`
+       SiteVerifyEndpoint string `json:"site_verify_endpoint"`
 }
 
 type GoogleCaptchaResponse struct {
@@ -88,7 +89,11 @@ func (c *Captcha) Verify(captcha, userInput string) (pass 
bool) {
        }
        cli := &http.Client{}
        cli.Timeout = 10 * time.Second
-       resp, err := 
cli.PostForm("https://www.recaptcha.net/recaptcha/api/siteverify";, 
map[string][]string{
+       siteVerifyEndpoint := c.Config.SiteVerifyEndpoint
+       if siteVerifyEndpoint == "" {
+               siteVerifyEndpoint = 
"https://www.google.com/recaptcha/api/siteverify";
+       }
+       resp, err := cli.PostForm(siteVerifyEndpoint, map[string][]string{
                "secret":   {c.Config.SecretKey},
                "response": {userInput},
        })
@@ -135,6 +140,17 @@ func (c *Captcha) ConfigFields() []plugin.ConfigField {
                        },
                        Value: c.Config.SecretKey,
                },
+               {
+                       Name:        "site_verify_endpoint",
+                       Type:        plugin.ConfigTypeInput,
+                       Title:       
plugin.MakeTranslator(i18n.ConfigSiteVerifyEndpointTitle),
+                       Description: 
plugin.MakeTranslator(i18n.ConfigSiteVerifyEndpointDescription),
+                       Required:    false,
+                       UIOptions: plugin.ConfigFieldUIOptions{
+                               InputType: plugin.InputTypeText,
+                       },
+                       Value: c.Config.SiteVerifyEndpoint,
+               },
        }
 }
 

Reply via email to