liuxiaolong
2019-10-29 f9c3e6809dc080cd55cfdc7573380aee4cef0b8f
middlewares/auth/auth.go
@@ -1,6 +1,7 @@
package auth
import (
   "fmt"
   "github.com/gin-gonic/gin"
   "net/http"
   "strings"
@@ -35,7 +36,16 @@
   outUserM[userId] = userId
}
func removeOutUser(userId string) {
func OutUser(userId string) bool {
   lock.Lock()
   defer lock.Unlock()
   if _,ok := outUserM[userId];ok{
      return true
   }
   return false
}
func RemoveOutUser(userId string) {
   lock.Lock()
   defer lock.Unlock()
   if _,ok := outUserM[userId];ok{
@@ -54,9 +64,18 @@
            c.Abort()
         }
         user := (*jwtDriver).User(c)
         fmt.Println("AuthHandler user:",user)
         if user == nil {
            util.ResponseFormat(c,code.TokenNotFound,"尚未登录,请登录")
            c.Abort()
            return
         }
         loginM := user.(map[string]interface{})
         userId := loginM["id"].(string)
         removeOutUser(userId)
         if OutUser(userId) {
            util.ResponseFormat(c,code.TokenNotFound,"尚未登录,请登录")
            c.Abort()
         }
         c.Next()
      } else {
         c.Next()