Kaynağa Gözat

update 完善优化代码的权限验证

Alvin 8 ay önce
ebeveyn
işleme
fe785a44e0

+ 17 - 9
game/game_cluster/nodes/webadmin/router/middleware.go

@@ -37,14 +37,22 @@ func Auth(settingObj cfacade.ProfileJSON) gin.HandlerFunc {
 			return
 		}
 
-		// 获取请求URL
-		// url := c.Request.URL.Path
-		// s, err := mdb.RDB.HGet(context.Background(), common.GetTokenKey(tokenString), url).Result()
-		// if err != nil {
-		// 	mhayaLogger.Warnf("Auth HGet s error: %s", err.Error())
-		// 	common.PackUnauthorizedResult(c, code.InternalError, "")
-		// 	return
-		// }
+		if result != constant.AdminAccess {
+			// 获取请求URL
+			url := c.Request.URL.Path
+			s, err := mdb.RDB.HGet(context.Background(), common.GetTokenKey(tokenString), url).Result()
+			if err != nil {
+				mhayaLogger.Warnf("Auth HGet s error: %s", err.Error())
+				common.PackUnauthorizedResult(c, code.InternalError, "")
+				return
+			}
+
+			// 检查是否有权限
+			if s == "" {
+				common.PackUnauthorizedResult(c, code.UnauthorizedError, "token is no auth")
+				return
+			}
+		}
 
 		ss, err := mdb.RDB.HGet(context.Background(), common.GetTokenKey(tokenString), constant.AdminAccess).Result()
 		if err != nil {
@@ -54,7 +62,7 @@ func Auth(settingObj cfacade.ProfileJSON) gin.HandlerFunc {
 		}
 
 		// 检查是否有权限
-		if ss == "" && result == "" {
+		if ss == "" {
 			common.PackUnauthorizedResult(c, code.UnauthorizedError, "token is no auth")
 			return
 		}