Skip to content

Commit

Permalink
gtoken resp Unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Sep 14, 2019
1 parent dfb5e39 commit b4e27b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions gtoken/gtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,18 @@ func (m *GfToken) getRequestToken(r *ghttp.Request) resp.Resp {
parts := strings.SplitN(authHeader, " ", 2)
if !(len(parts) == 2 && parts[0] == "Bearer") {
glog.Warning("[GToken]authHeader:" + authHeader + " get token key fail")
return resp.Fail("get token key fail")
return resp.Unauthorized("get token key fail", "")
} else if parts[1] == "" {
glog.Warning("[GToken]authHeader:" + authHeader + " get token fail")
return resp.Fail("get token fail")
return resp.Unauthorized("get token fail", "")
}

return resp.Succ(parts[1])
}

authHeader = r.GetPostString("token")
if authHeader == "" {
return resp.Fail("query token fail")
return resp.Unauthorized("query token fail", "")
}
return resp.Succ(authHeader)

Expand Down Expand Up @@ -278,7 +278,7 @@ func (m *GfToken) genToken(userKey string, data interface{}) resp.Resp {
// validToken 验证Token
func (m *GfToken) validToken(token string) resp.Resp {
if token == "" {
return resp.Fail("valid token empty")
return resp.Unauthorized("valid token empty", "")
}

decryptToken := m.DecryptToken(token)
Expand All @@ -298,7 +298,7 @@ func (m *GfToken) validToken(token string) resp.Resp {

if uuid != userCache["uuid"] {
glog.Error("[GToken]user auth error, decryptToken:" + decryptToken.Json() + " cacheValue:" + gconv.String(userCache))
return resp.Fail("user auth error")
return resp.Unauthorized("user auth error", "")
}

nowTime := gtime.Now().Millisecond()
Expand Down
4 changes: 2 additions & 2 deletions gtoken/gtoken_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (m *GfToken) getCache(cacheKey string) resp.Resp {
case CacheModeCache:
userCacheValue := gcache.Get(cacheKey)
if userCacheValue == nil {
return resp.Fail("login timeout or not login")
return resp.Unauthorized("login timeout or not login", "")
}
userCache = gconv.Map(userCacheValue)
case CacheModeRedis:
Expand All @@ -49,7 +49,7 @@ func (m *GfToken) getCache(cacheKey string) resp.Resp {
return resp.Error("cache get error")
}
if userCacheJson == nil {
return resp.Fail("login timeout or not login")
return resp.Unauthorized("login timeout or not login", "")
}

err = gjson.DecodeTo(userCacheJson, &userCache)
Expand Down

0 comments on commit b4e27b8

Please sign in to comment.