forked from golang/hotime
增加权限管理
This commit is contained in:
parent
9cfdfbac78
commit
f7410200e3
@ -677,6 +677,10 @@ func setMakeCodeLintener(name string, appIns *Application) {
|
|||||||
return isFinished
|
return isFinished
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
|
|
||||||
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
||||||
context.Display(2, "你还没有登录")
|
context.Display(2, "你还没有登录")
|
||||||
return true
|
return true
|
||||||
|
76
code.go
76
code.go
@ -453,13 +453,13 @@ var TptProject = Proj{
|
|||||||
|
|
||||||
hotimeName := that.RouterString[0]
|
hotimeName := that.RouterString[0]
|
||||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||||
if that.Session(fileConfig.GetString("table")+"_id").Data == nil {
|
|
||||||
|
|
||||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
that.Display(4, "找不到配置文件")
|
that.Display(4, "找不到配置文件")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
if that.Session(fileConfig.GetString("table")+"_id").Data == nil {
|
||||||
|
|
||||||
conf := ObjToMap(string(btes))
|
conf := ObjToMap(string(btes))
|
||||||
delete(conf, "menus")
|
delete(conf, "menus")
|
||||||
@ -468,17 +468,11 @@ var TptProject = Proj{
|
|||||||
that.Display(0, conf)
|
that.Display(0, conf)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//可读写配置
|
||||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
that.Display(4, "找不到配置文件")
|
|
||||||
}
|
|
||||||
|
|
||||||
conf := ObjToMap(string(btes))
|
conf := ObjToMap(string(btes))
|
||||||
menus := conf.GetSlice("menus")
|
menus := conf.GetSlice("menus")
|
||||||
|
|
||||||
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": fileConfig.GetString("table") + "_id"})
|
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").Data})
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
that.Display(2, "暂未登录")
|
that.Display(2, "暂未登录")
|
||||||
@ -497,14 +491,14 @@ var TptProject = Proj{
|
|||||||
|
|
||||||
for k1, _ := range menus {
|
for k1, _ := range menus {
|
||||||
v1 := menus.GetMap(k1)
|
v1 := menus.GetMap(k1)
|
||||||
if linkAuth[v1.GetString("name")] != nil {
|
if linkAuth[v1.GetString("table")] != nil {
|
||||||
v1["auth"] = linkAuth[v1.GetString("name")]
|
v1["auth"] = linkAuth[v1.GetString("table")]
|
||||||
}
|
}
|
||||||
|
v1menus := v1.GetSlice("menus")
|
||||||
for k2, _ := range v1.GetSlice("menus") {
|
for k2, _ := range v1menus {
|
||||||
v2 := menus.GetMap(k2)
|
v2 := menus.GetMap(k2)
|
||||||
if linkAuth[v2.GetString("name")] != nil {
|
if linkAuth[v2.GetString("table")] != nil {
|
||||||
v2["auth"] = linkAuth[v2.GetString("name")]
|
v2["auth"] = linkAuth[v2.GetString("table")]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,37 +509,57 @@ var TptProject = Proj{
|
|||||||
userAuth := user.GetMap("auth")
|
userAuth := user.GetMap("auth")
|
||||||
for k1, _ := range menus {
|
for k1, _ := range menus {
|
||||||
v1 := menus.GetMap(k1)
|
v1 := menus.GetMap(k1)
|
||||||
if userAuth[v1.GetString("name")] != nil {
|
if userAuth[v1.GetString("table")] != nil {
|
||||||
v1["auth"] = userAuth[v1.GetString("name")]
|
v1["auth"] = userAuth[v1.GetString("table")]
|
||||||
}
|
}
|
||||||
|
v1menus := v1.GetSlice("menus")
|
||||||
for k2, _ := range v1.GetSlice("menus") {
|
for k2, _ := range v1menus {
|
||||||
v2 := menus.GetMap(k2)
|
v2 := v1menus.GetMap(k2)
|
||||||
if userAuth[v2.GetString("name")] != nil {
|
if userAuth[v2.GetString("table")] != nil {
|
||||||
v2["auth"] = userAuth[v2.GetString("name")]
|
v2["auth"] = userAuth[v2.GetString("table")]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//不可读写数据
|
||||||
config := DeepCopyMap(that.MakeCodeRouter[hotimeName].Config).(Map)
|
config := DeepCopyMap(that.MakeCodeRouter[hotimeName].Config).(Map)
|
||||||
|
|
||||||
config["menus"] = menus
|
config["menus"] = menus
|
||||||
newTables := Map{}
|
newTables := Map{}
|
||||||
for k1, _ := range menus {
|
for k1, _ := range menus {
|
||||||
v1 := menus.GetMap(k1)
|
v1 := menus.GetMap(k1)
|
||||||
if config.GetMap("tables").GetMap(v1.GetString("name")) != nil {
|
if config.GetMap("tables").GetMap(v1.GetString("table")) != nil {
|
||||||
newTables[v1.GetString("name")] = config.GetMap("tables").GetMap(v1.GetString("name"))
|
newTables[v1.GetString("name")] = config.GetMap("tables").GetMap(v1.GetString("table"))
|
||||||
}
|
}
|
||||||
|
v1menus := v1.GetSlice("menus")
|
||||||
for k2, _ := range v1.GetSlice("menus") {
|
for k2, _ := range v1.GetSlice("menus") {
|
||||||
v2 := menus.GetMap(k2)
|
v2 := v1menus.GetMap(k2)
|
||||||
if config.GetMap("tables").GetMap(v2.GetString("name")) != nil {
|
if config.GetMap("tables").GetMap(v2.GetString("table")) != nil {
|
||||||
newTables[v2.GetString("name")] = config.GetMap("tables").GetMap(v2.GetString("name"))
|
//有自定义配置文件
|
||||||
|
if conf.GetMap("tables") != nil && conf.GetMap("tables").GetMap(v2.GetString("table")) != nil {
|
||||||
|
|
||||||
|
columns := config.GetMap("tables").GetMap(v2.GetString("table")).GetSlice("columns")
|
||||||
|
columnsConf := conf.GetMap("tables").GetMap(v2.GetString("table")).GetSlice("columns")
|
||||||
|
for k3, _ := range columns {
|
||||||
|
v3 := columns.GetMap(k3)
|
||||||
|
for k4, _ := range columnsConf {
|
||||||
|
v4 := columnsConf.GetMap(k4)
|
||||||
|
|
||||||
|
if v3.GetString("name") == v4.GetString("name") {
|
||||||
|
columns[k3] = columnsConf[k4]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newTables[v2.GetString("table")] = config.GetMap("tables").GetMap(v2.GetString("table"))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config["tables"] = menus
|
config["tables"] = newTables
|
||||||
|
|
||||||
that.Display(0, config)
|
that.Display(0, config)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user