updated

This commit is contained in:
landaiqing
2024-11-14 01:58:20 +08:00
parent c95d5fc041
commit 3b8e3df27a
83 changed files with 172212 additions and 343 deletions

View File

@@ -0,0 +1,35 @@
package verify
import (
"context"
"encoding/json"
"fmt"
"strconv"
"github.com/redis/go-redis/v9"
"github.com/wenlng/go-captcha/v2/rotate"
"schisandra-album-cloud-microservices/app/core/api/common/constant"
)
// VerifyRotateCaptcha verify rotate captcha
func VerifyRotateCaptcha(context context.Context, redis *redis.Client, angle int64, key string) bool {
cacheDataByte := redis.Get(context, constant.UserCaptchaPrefix+key).Val()
if len(cacheDataByte) == 0 {
return false
}
var dct *rotate.Block
if err := json.Unmarshal([]byte(cacheDataByte), &dct); err != nil {
return false
}
sAngle, err := strconv.ParseFloat(fmt.Sprintf("%v", angle), 64)
if err != nil {
return false
}
chkRet := rotate.CheckAngle(int64(sAngle), int64(dct.Angle), 2)
if chkRet {
return true
}
return false
}

View File

@@ -0,0 +1,36 @@
package verify
import (
"context"
"encoding/json"
"fmt"
"strconv"
"github.com/redis/go-redis/v9"
"github.com/wenlng/go-captcha/v2/slide"
"schisandra-album-cloud-microservices/app/core/api/common/constant"
)
// VerifySlideCaptcha verify slide captcha
func VerifySlideCaptcha(context context.Context, redis *redis.Client, point []int64, key string) bool {
cacheDataByte := redis.Get(context, constant.UserCaptchaPrefix+key).Val()
if len(cacheDataByte) == 0 {
return false
}
var dct *slide.Block
if err := json.Unmarshal([]byte(cacheDataByte), &dct); err != nil {
return false
}
chkRet := false
if 2 == len(point) {
sx, _ := strconv.ParseFloat(fmt.Sprintf("%v", point[0]), 64)
sy, _ := strconv.ParseFloat(fmt.Sprintf("%v", point[1]), 64)
chkRet = slide.CheckPoint(int64(sx), int64(sy), int64(dct.X), int64(dct.Y), 4)
}
if chkRet {
return true
}
return false
}