李伟乐 2 years ago
parent 629192ccbf
commit 6219c2acfa
  1. 11
      pkg/captcha/captcha.go

@ -17,9 +17,14 @@ var DefaultConfig = base64Captcha.DriverString{
Source: "1234567890qwertyuioplkjhgfdsazxcvbnm", Source: "1234567890qwertyuioplkjhgfdsazxcvbnm",
Fonts: []string{"wqy-microhei.ttc", "chromohv.ttf", "actionj.ttf", "RitaSmith.ttf"}, Fonts: []string{"wqy-microhei.ttc", "chromohv.ttf", "actionj.ttf", "RitaSmith.ttf"},
} }
var DefaultStore = base64Captcha.DefaultMemStore
func Generate(store base64Captcha.Store) (id, b64s string, err error) { func SetStore(store base64Captcha.Store) {
return base64Captcha.NewCaptcha(&DefaultConfig, store).Generate() DefaultStore = store
}
func Generate() (id, b64s string, err error) {
return base64Captcha.NewCaptcha(&DefaultConfig, DefaultStore).Generate()
} }
type redisStore struct { type redisStore struct {
@ -33,7 +38,7 @@ func NewRedisStore(redis *redis.Client) *redisStore {
} }
func (r *redisStore) Key(key string) string { func (r *redisStore) Key(key string) string {
return fmt.Sprintf("captach::%s", key) return fmt.Sprintf("captach:%s", key)
} }
func (r *redisStore) Set(id string, value string) error { func (r *redisStore) Set(id string, value string) error {
return r.redis.Set(r.Key(id), value, time.Second*3700).Err() return r.redis.Set(r.Key(id), value, time.Second*3700).Err()

Loading…
Cancel
Save