|
@@ -7,11 +7,11 @@ import (
|
|
|
"net/http"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/mhaya/game/game_cluster/internal/constant"
|
|
|
"github.com/mhaya/game/game_cluster/internal/mdb/models"
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
- "github.com/mhaya/game/game_cluster/internal/constant"
|
|
|
"github.com/mhaya/game/game_cluster/internal/mdb"
|
|
|
)
|
|
|
|
|
@@ -26,6 +26,9 @@ func Auth() gin.HandlerFunc {
|
|
|
}
|
|
|
result, err := mdb.RDB.Get(context.Background(), tokenString).Result()
|
|
|
if err != nil {
|
|
|
+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
|
|
+ "msg": "token is empty",
|
|
|
+ })
|
|
|
return
|
|
|
}
|
|
|
if result == "" {
|
|
@@ -37,15 +40,16 @@ func Auth() gin.HandlerFunc {
|
|
|
// 获取请求URL
|
|
|
url := c.Request.URL.Path
|
|
|
s, _ := mdb.RDB.HGet(context.Background(), "admin::token::"+tokenString, url).Result()
|
|
|
- admin, _ := mdb.RDB.HGet(context.Background(), "admin::token::"+tokenString, constant.AdminAccess).Result()
|
|
|
+ ss, _ := mdb.RDB.HGet(context.Background(), "admin::token::"+tokenString, constant.AdminAccess).Result()
|
|
|
+ fmt.Println(ss)
|
|
|
// 检查是否有权限
|
|
|
- if s == "" && admin == "" {
|
|
|
+ if s == "" && result == "" {
|
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
|
|
"msg": "token is no auth",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if admin == "" {
|
|
|
+ if result == "" {
|
|
|
if err := checkIP(c); err != nil {
|
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
|
|
"msg": "ip is no auth",
|