验证码存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

@@ -8,7 +8,6 @@ import (
"git.rosy.net.cn/jx-print/globals"
"git.rosy.net.cn/jx-print/model"
"github.com/dchest/captcha"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"math/rand"
"net/http"
@@ -65,10 +64,12 @@ func Captcha(c *gin.Context, length ...int) {
h = length[2]
}
captchaId := captcha.NewLen(l)
session := sessions.Default(c)
session.Set(c.ClientIP()+model.SessionKey, captchaId)
_ = session.Save()
_ = Serve(c.Writer, c.Request, captchaId, ".png", "zh", false, w, h)
//session := sessions.Default(c)
//session.Set(c.ClientIP()+model.SessionKey, captchaId)
//_ = session.Save()
if err := SetKey(c.ClientIP()+model.SessionKey, captchaId, time.Minute*5); err == nil {
_ = Serve(c.Writer, c.Request, captchaId, ".png", "zh", false, w, h)
}
}
func Serve(w http.ResponseWriter, r *http.Request, id, ext, lang string, download bool, width, height int) error {