Skip to content

Commit

Permalink
feat(recaptcha): Site Verify Endpoint Config
Browse files Browse the repository at this point in the history
  • Loading branch information
lightumcc authored and LinkinStars committed Aug 6, 2024
1 parent a15252f commit 9e629d2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions captcha-google-v2/i18n/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions captcha-google-v2/i18n/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
5 changes: 5 additions & 0 deletions captcha-google-v2/i18n/zh_CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 输入上面的文本
Expand Down
18 changes: 17 additions & 1 deletion captcha-google-v2/recaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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},
})
Expand Down Expand Up @@ -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,
},
}
}

Expand Down

0 comments on commit 9e629d2

Please sign in to comment.