diff --git a/global/guard.go b/global/guard.go index 46deeebf..2edfb264 100644 --- a/global/guard.go +++ b/global/guard.go @@ -7,6 +7,7 @@ import ( "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" "github.com/yaoapp/xiang/user" + "github.com/yaoapp/xiang/xlog" ) // Guards 服务中间件 @@ -24,11 +25,15 @@ func bearerJWT(c *gin.Context) { } tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer ")) + if Conf.Mode == "debug" { + xlog.Printf("JWT: %s Secret: %s", tokenString, Conf.JWT.Secret) + } token, err := jwt.ParseWithClaims(tokenString, &user.JwtClaims{}, func(token *jwt.Token) (interface{}, error) { - return Conf.JWT.Secret, nil + return []byte(Conf.JWT.Secret), nil }) if err != nil { + xlog.Printf("JWT ParseWithClaims Error: %s", err) c.JSON(403, gin.H{"code": 403, "message": fmt.Sprintf("登录已过期或令牌失效(%s)", err)}) c.Abort() return diff --git a/user/user.go b/user/user.go index 349009d3..b1864f11 100644 --- a/user/user.go +++ b/user/user.go @@ -79,6 +79,7 @@ func MakeToken(row maps.Map, ExpiresAt int64) string { Type: row.Get("type").(string), Name: row.Get("name").(string), StandardClaims: jwt.StandardClaims{ + Id: fmt.Sprintf("%s_%d", row.Get("type"), row.Get("id")), Subject: fmt.Sprintf("%d", row.Get("id")), ExpiresAt: ExpiresAt, Issuer: fmt.Sprintf("%d", row.Get("id")), diff --git a/xiang/models/menu.json b/xiang/models/menu.json index 26c6151e..13dade13 100644 --- a/xiang/models/menu.json +++ b/xiang/models/menu.json @@ -57,6 +57,7 @@ "index": true }, { + "label": "状态", "name": "status", "type": "enum", "default": "enabled", diff --git a/xiang/tables/menu.json b/xiang/tables/menu.json new file mode 100644 index 00000000..6ecceab2 --- /dev/null +++ b/xiang/tables/menu.json @@ -0,0 +1,98 @@ +{ + "name": "菜单", + "version": "1.0.0", + "decription": "象传菜单", + "bind": { + "model": "xiang.menu" + }, + "apis": { + "search": { + "process": "models.xiang.menu.Paginate", + "guard": "-", + "default": [ + { + "withs": { + "children": { + "query": { + "select": ["name", "id"] + } + } + }, + "wheres": [{ "column": "parent", "op": "null" }] + }, + null, + 15 + ] + } + }, + "columns": {}, + "filters": {}, + "list": { + "primary": "id", + "layout": { + "columns": [ + { "name": "名称", "width": 6 }, + { "name": "父节点", "width": 6 }, + { "name": "图标", "width": 6 }, + { "name": "状态", "width": 6 }, + { "name": "路由", "width": 6 }, + { "name": "排列", "width": 4 }, + { "name": "block布局", "width": 4 }, + { "name": "显示", "width": 4 } + ], + "filters": [{ "name": "名称", "width": 6 }] + }, + "actions": { + "create": { + "type": "button", + "props": { + "label": "新建菜单", + "icon": "fas fa-plus" + } + }, + "view": {}, + "edit": {}, + "import": {}, + "update": {}, + "delete": {}, + "insert": {}, + "updateWhere": {}, + "deleteWhere": {}, + "updateSelect": {}, + "deleteSelect": {}, + "pagination": {}, + "setting": {} + } + }, + "edit": { + "primary": "id", + "layout": { + "fieldset": [ + { + "title": "基础信息", + "description": "", + "columns": [ + { "name": "名称", "width": 6 }, + { "name": "图标", "width": 6 }, + { "name": "路由", "width": 6 }, + { "name": "排列", "width": 6 }, + { "name": "block布局", "width": 6 }, + { "name": "显示", "width": 6 } + ] + } + ] + }, + "actions": { + "cancel": {}, + "save": { + "type": "button", + "props": { + "label": "保存" + } + }, + "delete": {} + } + }, + "insert": {}, + "view": {} +}