u
This commit is contained in:
1 parent
4e42a01b97
commit
428d370874
8 files changed
+84
-44
No files matched your search
@@ -2,9 +2,9 @@ package middleware
|
||||
|
||||
import (
|
||||
"base-framework/pkg/config"
|
||||
"base-framework/pkg/reponse"
|
||||
"base-framework/pkg/router"
|
||||
"base-framework/pkg/utils/jwt"
|
||||
"base-framework/pkg/utils/response"
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
@@ -20,7 +20,7 @@ func Auth() router.HandlerFunc {
|
||||
|
||||
// 缺少登录信息
|
||||
if tokenHeader == "" || userIdHeader == "" || orgIDHeader == "" {
|
||||
response.Error(c).Code(response.CodeNoLogin).Send()
|
||||
reponse.Error(c).Code(reponse.CodeNoLogin).Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func Auth() router.HandlerFunc {
|
||||
// Bearer token 格式校验
|
||||
parts := strings.Fields(tokenHeader)
|
||||
if len(parts) != 2 || strings.ToLower(parts[0]) != "bearer" {
|
||||
response.Error(c).Code(response.CodeInvalidToken).Send()
|
||||
reponse.Error(c).Code(reponse.CodeInvalidToken).Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -39,9 +39,9 @@ func Auth() router.HandlerFunc {
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, jwt.ErrTokenExpired):
|
||||
response.Error(c).Code(response.CodeLoginExpired).Send()
|
||||
reponse.Error(c).Code(reponse.CodeLoginExpired).Send()
|
||||
default:
|
||||
response.Error(c).Code(response.CodeInvalidToken).Send()
|
||||
reponse.Error(c).Code(reponse.CodeInvalidToken).Send()
|
||||
}
|
||||
c.Abort()
|
||||
return
|
||||
@@ -49,14 +49,14 @@ func Auth() router.HandlerFunc {
|
||||
|
||||
// user_id 校验
|
||||
if claims.UserID != userIdHeader {
|
||||
response.Error(c).Code(response.CodeInvalidToken).Send()
|
||||
reponse.Error(c).Code(reponse.CodeInvalidToken).Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// org_id 校验
|
||||
if claims.OrgID != orgIDHeader {
|
||||
response.Error(c).Code(response.CodeInvalidToken).Send()
|
||||
reponse.Error(c).Code(reponse.CodeInvalidToken).Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func Auth() router.HandlerFunc {
|
||||
}
|
||||
|
||||
if !hasOrg {
|
||||
response.Error(c).Code(response.CodeInvalidOrgCode).Send()
|
||||
reponse.Error(c).Code(reponse.CodeInvalidOrgCode).Send()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user