技术性调整
This commit is contained in:
@@ -420,6 +420,103 @@ var TptProject = Proj{
|
||||
|
||||
that.Display(0, filePath)
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
tableName := fileConfig.GetString("table")
|
||||
|
||||
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(tableName, data, that.Db)
|
||||
where := Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}
|
||||
|
||||
if len(inData) == 1 {
|
||||
inData["id"] = where["id"]
|
||||
where = Map{"AND": inData}
|
||||
} else if len(inData) > 1 {
|
||||
where["OR"] = inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
re := that.Db.Get(tableName, str, where)
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
seStr := "id," + column.GetString("value")
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||
seStr = seStr + ",phone"
|
||||
}
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
}
|
||||
|
||||
//权限设置
|
||||
if column["type"] == "auth" {
|
||||
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
|
||||
if err != nil {
|
||||
that.Display(4, "找不到权限配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
userAuth := re.GetMap("auth")
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if userAuth[v1.GetString("name")] != nil {
|
||||
v1["auth"] = userAuth[v1.GetString("name")]
|
||||
}
|
||||
for k2, _ := range v1.GetSlice("menus") {
|
||||
v2 := menus.GetMap(k2)
|
||||
if userAuth[v2.GetString("name")] != nil {
|
||||
v2["auth"] = userAuth[v2.GetString("name")]
|
||||
}
|
||||
}
|
||||
}
|
||||
re["auth"] = menus
|
||||
//that.Display(0,menus)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//如果有table字段则代为link
|
||||
if re["table"] != nil && re["table_id"] != nil {
|
||||
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][re.GetString("table")]
|
||||
v := re.GetCeilInt64("table_id")
|
||||
|
||||
seStr := "id," + column.GetString("value")
|
||||
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||
seStr = seStr + ",phone"
|
||||
}
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
|
||||
}
|
||||
re["table"] = fileConfig.GetString("table")
|
||||
that.Display(0, re)
|
||||
},
|
||||
"login": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
@@ -430,7 +527,16 @@ var TptProject = Proj{
|
||||
that.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||
|
||||
where := Map{"name": name}
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
||||
where["phone"] = name
|
||||
where = Map{"AND": Map{"OR": where}, "password": Md5(password)}
|
||||
} else {
|
||||
where["password"] = Md5(password)
|
||||
}
|
||||
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", where)
|
||||
|
||||
if user == nil {
|
||||
that.Display(5, "登录失败")
|
||||
@@ -440,8 +546,10 @@ var TptProject = Proj{
|
||||
that.Session(fileConfig.GetString("table")+"_name", name)
|
||||
delete(user, "password")
|
||||
user["table"] = fileConfig.GetString("table")
|
||||
user["token"] = that.SessionId
|
||||
that.Display(0, user)
|
||||
},
|
||||
|
||||
"logout": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
@@ -496,7 +604,7 @@ var TptProject = Proj{
|
||||
}
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := menus.GetMap(k2)
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if linkAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("table")]
|
||||
}
|
||||
@@ -559,9 +667,9 @@ var TptProject = Proj{
|
||||
}
|
||||
}
|
||||
|
||||
config["tables"] = newTables
|
||||
conf["tables"] = newTables
|
||||
|
||||
that.Display(0, config)
|
||||
that.Display(0, conf)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user