diff --git a/stores/redisstore/go.mod b/stores/redisstore/go.mod index 184065b..8e88d51 100644 --- a/stores/redisstore/go.mod +++ b/stores/redisstore/go.mod @@ -2,4 +2,7 @@ module github.com/clevergo/captchas/stores/redisstore go 1.14 -require github.com/go-redis/redis/v7 v7.2.0 +require ( + github.com/clevergo/captchas v0.3.2 + github.com/go-redis/redis/v7 v7.2.0 +) diff --git a/stores/redisstore/go.sum b/stores/redisstore/go.sum index 4d3b693..90be41c 100644 --- a/stores/redisstore/go.sum +++ b/stores/redisstore/go.sum @@ -1,3 +1,5 @@ +github.com/clevergo/captchas v0.3.2 h1:/P/Lc8umYp052aGeyiQf8a8mED+g+lmZLqmogMrt1e0= +github.com/clevergo/captchas v0.3.2/go.mod h1:MgQIvLx9mhOoScMJnSFvXuqbAQVIwWtLJ862K1jRvR8= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-redis/redis/v7 v7.2.0 h1:CrCexy/jYWZjW0AyVoHlcJUeZN19VWlbepTh1Vq6dJs= diff --git a/stores/redisstore/store.go b/stores/redisstore/store.go index 0ab9103..694e20a 100644 --- a/stores/redisstore/store.go +++ b/stores/redisstore/store.go @@ -7,6 +7,7 @@ package redisstore import ( "time" + "github.com/clevergo/captchas" "github.com/go-redis/redis/v7" ) @@ -67,11 +68,16 @@ func (s *Store) Get(id string, clear bool) (string, error) { return "", err } val, err := get.Result() + isNil := false if err != nil { + isNil = err == redis.Nil + if isNil { + return "", captchas.ErrCaptchaIncorrect + } return "", err } - if clear { + if clear && !isNil { if _, err = del.Result(); err != nil { return "", err }