123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package middleware
- import (
- "fmt"
- "git.getensh.com/common/gopkgs/cache"
- "github.com/tidwall/gjson"
- "property-system-gateway/errors"
- "strings"
- )
- const SystemPermissionChangeKeyPrefix = "system_permission_change_"
- const GlobalPermissionKey = "property_global_permission"
- func gloablePermissionTime(gardenId int64) string {
- key := fmt.Sprintf("%s%d", GlobalPermissionKey, gardenId)
- str, _ := cache.Redis().Get(key)
- return str
- }
- func userPermissionTime(uid int64) string {
- key := fmt.Sprintf("%s%d", SystemPermissionChangeKeyPrefix, uid)
- str, _ := cache.Redis().Get(key)
- return str
- }
- func checkPermission(routers map[string]gjson.Result, router string, uid int64, gPermissionTime string, uPermissionTime string) error {
- //手机号登录选择账户不作权限检查; 获取权限不做检查
- if strings.Contains(router, "user/choose_user") || strings.Contains(router, "permission_reget") {
- return nil
- }
- array := strings.Split(router, "?")
- array = strings.Split(array[0], "/")
- path := ""
- fmt.Printf("has permission:%v\n", routers)
- // 逐个匹配路径
- for _, v := range array {
- if v == "" {
- continue
- }
- if v == "api" || v == "v1" {
- continue
- }
- if path == "" {
- path = v
- } else {
- path = path + "/" + v
- }
- fmt.Printf("now path:%v\n", path)
- if _, ok := routers[path]; ok {
- return nil
- }
- }
- return errors.PermissionError
- }
|