🏗️ microservice fabric splitting
This commit is contained in:
47
common/captcha/verify/verify_basic_text_captcha.go
Normal file
47
common/captcha/verify/verify_basic_text_captcha.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package verify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/wenlng/go-captcha/v2/click"
|
||||
)
|
||||
|
||||
// VerifyBasicTextCaptcha verify basic text captcha
|
||||
func VerifyBasicTextCaptcha(dots string, key string, redis *redis.Client, ctx context.Context) bool {
|
||||
cacheDataByte, err := redis.Get(ctx, constant.UserCaptchaPrefix+key).Bytes()
|
||||
if len(cacheDataByte) == 0 || err != nil {
|
||||
return false
|
||||
}
|
||||
src := strings.Split(dots, ",")
|
||||
|
||||
var dct map[int]*click.Dot
|
||||
if err := json.Unmarshal(cacheDataByte, &dct); err != nil {
|
||||
|
||||
return false
|
||||
}
|
||||
chkRet := false
|
||||
if (len(dct) * 2) == len(src) {
|
||||
for i := 0; i < len(dct); i++ {
|
||||
dot := dct[i]
|
||||
j := i * 2
|
||||
k := i*2 + 1
|
||||
sx, _ := strconv.ParseFloat(fmt.Sprintf("%v", src[j]), 64)
|
||||
sy, _ := strconv.ParseFloat(fmt.Sprintf("%v", src[k]), 64)
|
||||
|
||||
chkRet = click.CheckPoint(int64(sx), int64(sy), int64(dot.X), int64(dot.Y), int64(dot.Width), int64(dot.Height), 0)
|
||||
if !chkRet {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if chkRet {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user