@ -3,6 +3,12 @@ package middleware
import (
import (
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"io"
"net/http"
"net/url"
"strings"
"time"
"github.com/cloudreve/Cloudreve/v4/application/dependency"
"github.com/cloudreve/Cloudreve/v4/application/dependency"
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
"github.com/cloudreve/Cloudreve/v4/pkg/recaptcha"
"github.com/cloudreve/Cloudreve/v4/pkg/recaptcha"
@ -11,11 +17,6 @@ import (
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
"github.com/mojocn/base64Captcha"
"io"
"net/http"
"net/url"
"strings"
"time"
)
)
type req struct {
type req struct {
@ -133,7 +134,7 @@ func CaptchaRequired(enabled func(c *gin.Context) bool) gin.HandlerFunc {
break
break
case setting . CaptchaCap :
case setting . CaptchaCap :
captchaSetting := settings . CapCaptcha ( c )
captchaSetting := settings . CapCaptcha ( c )
if captchaSetting . InstanceURL == "" || captchaSetting . KeyID == "" || captchaSetting . Key Secret == "" {
if captchaSetting . InstanceURL == "" || captchaSetting . Site Key == "" || captchaSetting . SecretKey == "" {
l . Warning ( "Cap verification failed: missing configuration" )
l . Warning ( "Cap verification failed: missing configuration" )
c . JSON ( 200 , serializer . ErrWithDetails ( c , serializer . CodeCaptchaError , "Captcha configuration error" , nil ) )
c . JSON ( 200 , serializer . ErrWithDetails ( c , serializer . CodeCaptchaError , "Captcha configuration error" , nil ) )
c . Abort ( )
c . Abort ( )
@ -146,9 +147,10 @@ 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" } } ) ,
)
)
capEndpoint := strings . TrimSuffix ( captchaSetting . InstanceURL , "/" ) + "/" + captchaSetting . KeyID + "/siteverify"
// Cap 2.0 API format: /{siteKey}/siteverify
capEndpoint := strings . TrimSuffix ( captchaSetting . InstanceURL , "/" ) + "/" + captchaSetting . SiteKey + "/siteverify"
requestBody := map [ string ] string {
requestBody := map [ string ] string {
"secret" : captchaSetting . Key Secret,
"secret" : captchaSetting . SecretKey ,
"response" : service . Ticket ,
"response" : service . Ticket ,
}
}
requestData , err := json . Marshal ( requestBody )
requestData , err := json . Marshal ( requestBody )