验证码存redis

This commit is contained in:
suyl
2021-07-13 18:36:23 +08:00
parent 826975c1b3
commit 7e00b58050
2 changed files with 20 additions and 10 deletions

View File

@@ -7,7 +7,6 @@ import (
"git.rosy.net.cn/jx-print/model"
"git.rosy.net.cn/jx-print/utils"
"github.com/dchest/captcha"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"net/http"
"strings"
@@ -93,10 +92,9 @@ func callFunc(c *gin.Context, worker func() (retVal interface{}, errCode string,
}
func captchaVerify(c *gin.Context, code string) bool {
session := sessions.Default(c)
if captchaId := session.Get(c.ClientIP() + model.SessionKey); captchaId != nil {
session.Delete(c.ClientIP() + model.SessionKey)
_ = session.Save()
//session := sessions.Default(c)
if captchaId := utils.GetKet(c.ClientIP() + model.SessionKey); captchaId != nil {
utils.DelKey(c.ClientIP() + model.SessionKey)
if captcha.VerifyString(captchaId.(string), code) {
return true
} else {
@@ -105,6 +103,17 @@ func captchaVerify(c *gin.Context, code string) bool {
} else {
return false
}
//if captchaId := session.Get(c.ClientIP() + model.SessionKey); captchaId != nil {
// session.Delete(c.ClientIP() + model.SessionKey)
// _ = session.Save()
// if captcha.VerifyString(captchaId.(string), code) {
// return true
// } else {
// return false
// }
//} else {
// return false
//}
}
func buildErrJson(c *gin.Context, err error) {