commit
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
c985e45c71
commit
52fd93ef04
@ -0,0 +1,42 @@
|
|||||||
|
package CaptchaController
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"dsSzxy/Utils/RedisUtil"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ctx = context.Background()
|
||||||
|
|
||||||
|
const CAPTCHA = "captcha:"
|
||||||
|
|
||||||
|
type RedisStore struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set set a capt
|
||||||
|
func (r RedisStore) Set(id string, value string) {
|
||||||
|
key := CAPTCHA + id
|
||||||
|
RedisUtil.SET(key, value, time.Minute*2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get get a capt
|
||||||
|
func (r RedisStore) Get(id string, clear bool) string {
|
||||||
|
key := CAPTCHA + id
|
||||||
|
|
||||||
|
val, err := RedisUtil.GET(key)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if clear {
|
||||||
|
RedisUtil.DEL(key)
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify verify a capt
|
||||||
|
func (r RedisStore) Verify(id, answer string, clear bool) bool {
|
||||||
|
v := RedisStore{}.Get(id, clear)
|
||||||
|
return v == answer
|
||||||
|
}
|
Loading…
Reference in new issue