ip session
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user