mirror of https://github.com/cloudreve/Cloudreve
refactor(captcha): remove Cap 1.x compatibility, keep only 2.x support
parent
65a47008ab
commit
e92879aadd
|
@ -147,24 +147,11 @@ func CaptchaRequired(enabled func(c *gin.Context) bool) gin.HandlerFunc {
|
||||||
request2.WithHeader(http.Header{"Content-Type": []string{"application/json"}}),
|
request2.WithHeader(http.Header{"Content-Type": []string{"application/json"}}),
|
||||||
)
|
)
|
||||||
|
|
||||||
var capEndpoint string
|
// Cap 2.0 API format: /{siteKey}/siteverify
|
||||||
var requestBody map[string]string
|
capEndpoint := strings.TrimSuffix(captchaSetting.InstanceURL, "/") + "/" + captchaSetting.SiteKey + "/siteverify"
|
||||||
|
requestBody := map[string]string{
|
||||||
// Support both 1.x and 2.x API formats
|
"secret": captchaSetting.SecretKey,
|
||||||
if captchaSetting.Version == "1.x" {
|
"response": service.Ticket,
|
||||||
// Version 1.x: /api/{keyID}/siteverify
|
|
||||||
capEndpoint = strings.TrimSuffix(captchaSetting.InstanceURL, "/") + "/api/" + captchaSetting.SiteKey + "/siteverify"
|
|
||||||
requestBody = map[string]string{
|
|
||||||
"secret": captchaSetting.SecretKey,
|
|
||||||
"response": service.Ticket,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Version 2.x (default): /{siteKey}/siteverify
|
|
||||||
capEndpoint = strings.TrimSuffix(captchaSetting.InstanceURL, "/") + "/" + captchaSetting.SiteKey + "/siteverify"
|
|
||||||
requestBody = map[string]string{
|
|
||||||
"secret": captchaSetting.SecretKey,
|
|
||||||
"response": service.Ticket,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
requestData, err := json.Marshal(requestBody)
|
requestData, err := json.Marshal(requestBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -671,7 +671,6 @@ func (s *settingProvider) CapCaptcha(ctx context.Context) *Cap {
|
||||||
InstanceURL: s.getString(ctx, "captcha_cap_instance_url", ""),
|
InstanceURL: s.getString(ctx, "captcha_cap_instance_url", ""),
|
||||||
SiteKey: s.getString(ctx, "captcha_cap_key_id", ""),
|
SiteKey: s.getString(ctx, "captcha_cap_key_id", ""),
|
||||||
SecretKey: s.getString(ctx, "captcha_cap_key_secret", ""),
|
SecretKey: s.getString(ctx, "captcha_cap_key_secret", ""),
|
||||||
Version: s.getString(ctx, "captcha_cap_version", "1.x"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ type Cap struct {
|
||||||
InstanceURL string
|
InstanceURL string
|
||||||
SiteKey string
|
SiteKey string
|
||||||
SecretKey string
|
SecretKey string
|
||||||
Version string // "1.x" or "2.x"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SMTP struct {
|
type SMTP struct {
|
||||||
|
|
|
@ -31,7 +31,6 @@ type SiteConfig struct {
|
||||||
TurnstileSiteID string `json:"turnstile_site_id,omitempty"`
|
TurnstileSiteID string `json:"turnstile_site_id,omitempty"`
|
||||||
CapInstanceURL string `json:"captcha_cap_instance_url,omitempty"`
|
CapInstanceURL string `json:"captcha_cap_instance_url,omitempty"`
|
||||||
CapKeyID string `json:"captcha_cap_key_id,omitempty"`
|
CapKeyID string `json:"captcha_cap_key_id,omitempty"`
|
||||||
CapVersion string `json:"captcha_cap_version,omitempty"`
|
|
||||||
RegisterEnabled bool `json:"register_enabled,omitempty"`
|
RegisterEnabled bool `json:"register_enabled,omitempty"`
|
||||||
TosUrl string `json:"tos_url,omitempty"`
|
TosUrl string `json:"tos_url,omitempty"`
|
||||||
PrivacyPolicyUrl string `json:"privacy_policy_url,omitempty"`
|
PrivacyPolicyUrl string `json:"privacy_policy_url,omitempty"`
|
||||||
|
@ -139,7 +138,6 @@ func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) {
|
||||||
ReCaptchaKey: reCaptcha.Key,
|
ReCaptchaKey: reCaptcha.Key,
|
||||||
CapInstanceURL: capCaptcha.InstanceURL,
|
CapInstanceURL: capCaptcha.InstanceURL,
|
||||||
CapKeyID: capCaptcha.SiteKey,
|
CapKeyID: capCaptcha.SiteKey,
|
||||||
CapVersion: capCaptcha.Version,
|
|
||||||
AppPromotion: appSetting.Promotion,
|
AppPromotion: appSetting.Promotion,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue