:art:验证码接口

This commit is contained in:
coward
2024-03-06 17:31:39 +08:00
parent c820672f89
commit 2ac91bf012
7 changed files with 107 additions and 32 deletions

View File

@@ -3,6 +3,7 @@ package compoment
import (
"context"
"fmt"
"strings"
"time"
"wireguard-dashboard/client"
"wireguard-dashboard/constant"
@@ -27,7 +28,17 @@ func (CaptchaStore) Set(id string, value string) error {
// @param clear
// @return string
func (CaptchaStore) Get(id string, clear bool) string {
val, err := client.Redis.Get(context.Background(), fmt.Sprintf("%s:%s", constant.Captcha, id)).Result()
if err != nil {
return ""
}
if clear {
client.Redis.Del(context.Background(), fmt.Sprintf("%s:%s", constant.Captcha, id))
return val
}
return val
}
// Verify
@@ -37,6 +48,7 @@ func (CaptchaStore) Get(id string, clear bool) string {
// @param answer
// @param clear
// @return bool
func (CaptchaStore) Verify(id, answer string, clear bool) bool {
func (c CaptchaStore) Verify(id, answer string, clear bool) bool {
storeAnswer := c.Get(id, clear)
return strings.ToUpper(answer) == strings.ToUpper(storeAnswer)
}