:art:验证码接口
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user