This commit is contained in:
aozhiwei 2024-07-13 18:32:00 +08:00
parent e25b0665f2
commit a475fb982a
3 changed files with 9 additions and 11 deletions

View File

@ -2,26 +2,21 @@ package middleware
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
//. "main/global" . "main/global"
//"net/http" "net/http"
//"strings"
) )
func Auth() gin.HandlerFunc { func Auth() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
/*
token := c.Request.Header.Get("Authorization") token := c.Request.Header.Get("Authorization")
strArr := strings.Split(token, "|") s := GetSessionMgr().GetSessionByToken(token)
authToken := GetApp().GetSessionAccountId(strArr[0]) if s == nil {
if token == "" || token != authToken {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 50014, "code": 50014,
"message": "未登录或非法访问", "message": "未登录或非法访问",
}) })
response.FailWithDetailed(gin.H{"reload": true}, "未登录或非法访问", c)
c.Abort() c.Abort()
return return
}*/ }
c.Next()
} }
} }

View File

@ -2,6 +2,7 @@ package session
import ( import (
"f5" "f5"
"strings"
) )
type session struct { type session struct {
@ -25,7 +26,7 @@ func (this *session) GetLoginTime() int32 {
func newSession(accountAddress string, token string) *session { func newSession(accountAddress string, token string) *session {
p := new(session) p := new(session)
p.accountAddress = accountAddress p.accountAddress = strings.ToLower(accountAddress)
p.token = token p.token = token
p.loginTime = int32(f5.GetApp().GetRealSeconds()) p.loginTime = int32(f5.GetApp().GetRealSeconds())
return p return p

View File

@ -48,6 +48,8 @@ func (this *sessionMgr) AddSession(accountAddress string, token string) common.S
} }
} }
s := newSession(accountAddress, token) s := newSession(accountAddress, token)
this.addressHash.Store(accountAddress, s)
this.sessionHash.Store(token, s)
return s return s
} }