You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
689 B
43 lines
689 B
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
|
|
}
|