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"}}),
|
||||
)
|
||||
|
||||
var capEndpoint string
|
||||
var requestBody map[string]string
|
||||
|
||||
// Support both 1.x and 2.x API formats
|
||||
if captchaSetting.Version == "1.x" {
|
||||
// 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,
|
||||
}
|
||||
// Cap 2.0 API format: /{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)
|
||||
if err != nil {
|
||||
|
|
|
@ -671,7 +671,6 @@ func (s *settingProvider) CapCaptcha(ctx context.Context) *Cap {
|
|||
InstanceURL: s.getString(ctx, "captcha_cap_instance_url", ""),
|
||||
SiteKey: s.getString(ctx, "captcha_cap_key_id", ""),
|
||||
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
|
||||
SiteKey string
|
||||
SecretKey string
|
||||
Version string // "1.x" or "2.x"
|
||||
}
|
||||
|
||||
type SMTP struct {
|
||||
|
|
|
@ -31,7 +31,6 @@ type SiteConfig struct {
|
|||
TurnstileSiteID string `json:"turnstile_site_id,omitempty"`
|
||||
CapInstanceURL string `json:"captcha_cap_instance_url,omitempty"`
|
||||
CapKeyID string `json:"captcha_cap_key_id,omitempty"`
|
||||
CapVersion string `json:"captcha_cap_version,omitempty"`
|
||||
RegisterEnabled bool `json:"register_enabled,omitempty"`
|
||||
TosUrl string `json:"tos_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,
|
||||
CapInstanceURL: capCaptcha.InstanceURL,
|
||||
CapKeyID: capCaptcha.SiteKey,
|
||||
CapVersion: capCaptcha.Version,
|
||||
AppPromotion: appSetting.Promotion,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue