ip session

This commit is contained in:
suyl
2021-07-13 18:25:05 +08:00
parent e41dbfc9cc
commit 826975c1b3
3 changed files with 3 additions and 6 deletions

View File

@@ -94,9 +94,8 @@ 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(model.SessionKey); captchaId != nil {
globals.SugarLogger.Debugf("captchaVerify capid :%v", captchaId)
session.Delete(model.SessionKey)
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
@@ -104,7 +103,6 @@ func captchaVerify(c *gin.Context, code string) bool {
return false
}
} else {
globals.SugarLogger.Debugf("captchaVerify2 capid :%v", captchaId)
return false
}
}

View File

@@ -37,7 +37,6 @@ func RegisterUser(c *gin.Context) {
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
return
}
globals.SugarLogger.Debugf("Begin API :%s params: %v ip: %s", c.Request.URL, utils.Format4Output(user, true))
if !captchaVerify(c, user.Code) {
c.JSON(http.StatusOK, &CallBack{
Code: model.ErrCodeNormal,

View File

@@ -66,7 +66,7 @@ func Captcha(c *gin.Context, length ...int) {
}
captchaId := captcha.NewLen(l)
session := sessions.Default(c)
session.Set(model.SessionKey, captchaId)
session.Set(c.ClientIP()+model.SessionKey, captchaId)
_ = session.Save()
_ = Serve(c.Writer, c.Request, captchaId, ".png", "zh", false, w, h)
}