package middleware import ( "fmt" "github.com/gin-gonic/gin" "kefu/models" "kefu/types" "time" ) // 验证用中间件 func KefuAccountCheck(c *gin.Context) { entId := c.Param("entId") kefuName := c.Param("kefuName") kefuInfo := models.FindUserByUid(entId) if kefuInfo.ID == 0 || kefuInfo.Name != kefuName || kefuInfo.Status == 1 { c.JSON(200, gin.H{ "code": types.ApiCode.ACCOUNT_NO_EXIST, "msg": types.ApiCode.GetMessage(types.ApiCode.ACCOUNT_NO_EXIST), }) c.Abort() return } nowSecond := time.Now().Unix() expireSecond := kefuInfo.ExpiredAt.Unix() if models.FindConfig("KefuExpired") == "on" && expireSecond < nowSecond { logContent := fmt.Sprintf("'%s'账户过期:%d,访问时间:%d", kefuInfo.Name, expireSecond, nowSecond) go models.CreateFlyLog(kefuInfo.EntId, c.ClientIP(), logContent, "user") c.JSON(200, gin.H{ "code": types.ApiCode.ACCOUNT_EXPIRED, "msg": types.ApiCode.GetMessage(types.ApiCode.ACCOUNT_EXPIRED), }) c.Abort() return } c.Set("kefuInfo", kefuInfo) }