From 62cf625fe9e7bf4fb57c5df0ec9ba08329525a64 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Mon, 30 Aug 2021 07:36:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A1=A8=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/config.go | 1 + code/makecode.go | 24 ++++++--- code/template.go | 23 ++++++++ example/admin/init.go | 47 +++++++++++++++- example/app/admin.go | 107 ------------------------------------- example/app/init.go | 3 -- example/app/org.go | 107 ------------------------------------- example/app/role.go | 107 ------------------------------------- example/config/config.json | 2 +- example/main.go | 11 ++++ 10 files changed, 100 insertions(+), 332 deletions(-) delete mode 100644 example/app/admin.go delete mode 100644 example/app/org.go delete mode 100644 example/app/role.go diff --git a/code/config.go b/code/config.go index 8fd83bb..2fa98a9 100644 --- a/code/config.go +++ b/code/config.go @@ -84,6 +84,7 @@ var ColumnNameType = []ColumnShow{ {"modify_time", false, false, true, false, "", false}, {"image", false, true, true, false, "image", false}, {"img", false, true, true, false, "image", false}, + {"avatar", false, true, true, false, "image", false}, {"file", false, true, true, false, "file", false}, {"age", false, true, true, false, "", false}, {"email", false, true, true, false, "", false}, diff --git a/code/makecode.go b/code/makecode.go index a7334c1..5ccd3d7 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -124,6 +124,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { } //idSlice=append(idSlice,nowTables) for _, v := range nowTables { + if v.GetString("name") == "cached" { + continue + } if that.TableConfig.GetMap(v.GetString("name")) == nil { if v.GetString("label") == "" { v["label"] = v.GetString("name") @@ -181,14 +184,14 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { coloum := that.TableColumns[v.GetString("name")][info.GetString("name")] if coloum == nil { - //根据类型判断真实类型 for k, v := range ColumnDataType { - if strings.Contains(info.GetString("type"), k) { + if strings.Contains(info.GetString("type"), k) || strings.Contains(info.GetString("name"), k) { info["type"] = v break } } + coloum = Map{ "name": info.GetString("name"), "type": info.GetString("type"), @@ -516,10 +519,15 @@ func (that *MakeCode) Add(table string, req *http.Request) Map { return nil } reqValue := req.FormValue(v.GetString("name")) - if reqValue == "" && strings.Contains(v.GetString("name"), "id") { + if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") { data[v.GetString("name")] = nil } else { - data[v.GetString("name")] = reqValue + if v.GetString("type") == "password" { + data[v.GetString("name")] = Md5(reqValue) + } else { + data[v.GetString("name")] = reqValue + } + } } @@ -539,10 +547,14 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map { } if v.Get("edit") == nil || v.GetBool("edit") { reqValue := req.FormValue(v.GetString("name")) - if reqValue == "" { + if reqValue == "" || reqValue == "null" { continue } - data[v.GetString("name")] = reqValue + if v.GetString("type") == "password" { + data[v.GetString("name")] = Md5(reqValue) + } else { + data[v.GetString("name")] = reqValue + } } } diff --git a/code/template.go b/code/template.go index 584e79f..6520e29 100644 --- a/code/template.go +++ b/code/template.go @@ -4,6 +4,7 @@ var InitTpt = `package {{name}} import ( . "../../../hotime" + . "../../../hotime/common" ) var ID = "{{id}}" @@ -12,6 +13,28 @@ var ID = "{{id}}" var Project = Proj{ //"user": UserCtr, {{tablesCtr}} + "hotime":Ctr{ + "login": func(this *Context) { + name:=this.Req.FormValue("name") + password:=this.Req.FormValue("password") + if name==""||password==""{ + this.Display(3,"参数不足") + return + } + user:=this.Db.Get("{{name}}","*",Map{"AND":Map{"name":name,"password":Md5(password)}}) + if user==nil{ + this.Display(5,"登录失败") + return + } + this.Session("id",user.GetCeilInt("id")) + this.Session("name",name) + this.Display(0,"登录成功") + }, + "logout": func(this *Context) { + this.Session("id",nil) + this.Session("name",nil) + this.Display(0,"退出登录成功") + }, } ` var CtrTpt = `package {{name}} diff --git a/example/admin/init.go b/example/admin/init.go index 6e94762..441e119 100644 --- a/example/admin/init.go +++ b/example/admin/init.go @@ -2,9 +2,10 @@ package admin import ( . "../../../hotime" + . "../../../hotime/common" ) -var ID = "f3fb4577ad6c15aedadd869e2bf6663c" +var ID = "3c5fc9732b8ddcb0a91b428976f2ce86" // Project 管理端项目 var Project = Proj{ @@ -16,4 +17,48 @@ var Project = Proj{ "org": orgCtr, "role": roleCtr, "user": userCtr, + "hotime": Ctr{ + "login": func(this *Context) { + name := this.Req.FormValue("name") + password := this.Req.FormValue("password") + if name == "" || password == "" { + this.Display(3, "参数不足") + return + } + user := this.Db.Get("admin", "*", Map{"AND": Map{"name": name, "password": Md5(password)}}) + if user == nil { + this.Display(5, "登录失败") + return + } + this.Session("id", user.GetCeilInt("id")) + this.Session("name", name) + this.Display(0, "登录成功") + }, + "logout": func(this *Context) { + this.Session("id", nil) + this.Session("name", nil) + this.Display(0, "退出登录成功") + }, + "info": func(that *Context) { + re := that.Db.Get("admin", that.MakeCode.Info("admin"), Map{"id": that.Session("id").ToCeilInt()}) + + if re == nil { + that.Display(4, "找不到对应信息") + return + } + + for k, v := range re { + + column := that.MakeCode.TableColumns["admin"][k] + if column == nil { + continue + } + if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { + re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) + } + } + + that.Display(0, re) + }, + }, } diff --git a/example/app/admin.go b/example/app/admin.go deleted file mode 100644 index fa75973..0000000 --- a/example/app/admin.go +++ /dev/null @@ -1,107 +0,0 @@ -package app - -import ( - . "../../../hotime" - . "../../../hotime/common" -) - -var adminCtr = Ctr{ - "info": func(that *Context) { - re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) - - if re == nil { - that.Display(4, "找不到对应信息") - return - } - - for k, v := range re { - - column := that.MakeCode.TableColumns[that.RouterString[1]][k] - if column == nil { - continue - } - if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { - re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) - } - } - - that.Display(0, re) - }, - "add": func(that *Context) { - inData := that.MakeCode.Add(that.RouterString[1], that.Req) - if inData == nil { - that.Display(3, "请求参数不足") - return - } - re := that.Db.Insert(that.RouterString[1], inData) - - if re == 0 { - that.Display(4, "无法插入对应数据") - return - } - - that.Display(0, re) - }, - "update": func(that *Context) { - inData := that.MakeCode.Edit(that.RouterString[1], that.Req) - if inData == nil { - that.Display(3, "没有找到要更新的数据") - return - } - re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) - - if re == 0 { - that.Display(4, "更新数据失败") - return - } - - that.Display(0, re) - }, - "remove": func(that *Context) { - re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) - - if re == 0 { - that.Display(4, "删除数据失败") - return - } - that.Display(0, re) - }, - "search": func(that *Context) { - - columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], that.Req, that.Db) - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - count := that.Db.Count(that.RouterString[1], leftJoin, where) - reData := that.Db.Page(page, pageSize). - PageSelect(that.RouterString[1], leftJoin, columnStr, where) - - for _, v := range reData { - for k, _ := range v { - column := that.MakeCode.TableColumns[that.RouterString[1]][k] - if column == nil { - continue - } - - if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { - parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) - v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = "" - if parentC != nil { - v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value")) - } - } - - } - } - - that.Display(0, Map{"count": count, "data": reData}) - }, -} diff --git a/example/app/init.go b/example/app/init.go index 9d5dd0a..f6c7038 100644 --- a/example/app/init.go +++ b/example/app/init.go @@ -17,12 +17,9 @@ var ID = "aad1472b19e575a71ee8f75629e27867" // Project 管理端项目 var Project = Proj{ //"user": UserCtr, - "admin": adminCtr, "category": categoryCtr, "ctg_order_date": ctg_order_dateCtr, "order": orderCtr, - "org": orgCtr, - "role": roleCtr, "user": userCtr, "sms": Sms, } diff --git a/example/app/org.go b/example/app/org.go deleted file mode 100644 index 99f0b6b..0000000 --- a/example/app/org.go +++ /dev/null @@ -1,107 +0,0 @@ -package app - -import ( - . "../../../hotime" - . "../../../hotime/common" -) - -var orgCtr = Ctr{ - "info": func(that *Context) { - re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) - - if re == nil { - that.Display(4, "找不到对应信息") - return - } - - for k, v := range re { - - column := that.MakeCode.TableColumns[that.RouterString[1]][k] - if column == nil { - continue - } - if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { - re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) - } - } - - that.Display(0, re) - }, - "add": func(that *Context) { - inData := that.MakeCode.Add(that.RouterString[1], that.Req) - if inData == nil { - that.Display(3, "请求参数不足") - return - } - re := that.Db.Insert(that.RouterString[1], inData) - - if re == 0 { - that.Display(4, "无法插入对应数据") - return - } - - that.Display(0, re) - }, - "update": func(that *Context) { - inData := that.MakeCode.Edit(that.RouterString[1], that.Req) - if inData == nil { - that.Display(3, "没有找到要更新的数据") - return - } - re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) - - if re == 0 { - that.Display(4, "更新数据失败") - return - } - - that.Display(0, re) - }, - "remove": func(that *Context) { - re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) - - if re == 0 { - that.Display(4, "删除数据失败") - return - } - that.Display(0, re) - }, - "search": func(that *Context) { - - columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], that.Req, that.Db) - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - count := that.Db.Count(that.RouterString[1], leftJoin, where) - reData := that.Db.Page(page, pageSize). - PageSelect(that.RouterString[1], leftJoin, columnStr, where) - - for _, v := range reData { - for k, _ := range v { - column := that.MakeCode.TableColumns[that.RouterString[1]][k] - if column == nil { - continue - } - - if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { - parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) - v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = "" - if parentC != nil { - v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value")) - } - } - - } - } - - that.Display(0, Map{"count": count, "data": reData}) - }, -} diff --git a/example/app/role.go b/example/app/role.go deleted file mode 100644 index 70542c6..0000000 --- a/example/app/role.go +++ /dev/null @@ -1,107 +0,0 @@ -package app - -import ( - . "../../../hotime" - . "../../../hotime/common" -) - -var roleCtr = Ctr{ - "info": func(that *Context) { - re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) - - if re == nil { - that.Display(4, "找不到对应信息") - return - } - - for k, v := range re { - - column := that.MakeCode.TableColumns[that.RouterString[1]][k] - if column == nil { - continue - } - if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { - re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) - } - } - - that.Display(0, re) - }, - "add": func(that *Context) { - inData := that.MakeCode.Add(that.RouterString[1], that.Req) - if inData == nil { - that.Display(3, "请求参数不足") - return - } - re := that.Db.Insert(that.RouterString[1], inData) - - if re == 0 { - that.Display(4, "无法插入对应数据") - return - } - - that.Display(0, re) - }, - "update": func(that *Context) { - inData := that.MakeCode.Edit(that.RouterString[1], that.Req) - if inData == nil { - that.Display(3, "没有找到要更新的数据") - return - } - re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) - - if re == 0 { - that.Display(4, "更新数据失败") - return - } - - that.Display(0, re) - }, - "remove": func(that *Context) { - re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) - - if re == 0 { - that.Display(4, "删除数据失败") - return - } - that.Display(0, re) - }, - "search": func(that *Context) { - - columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], that.Req, that.Db) - page := ObjToInt(that.Req.FormValue("page")) - pageSize := ObjToInt(that.Req.FormValue("pageSize")) - - if page < 1 { - page = 1 - } - - if pageSize <= 0 { - pageSize = 20 - } - - count := that.Db.Count(that.RouterString[1], leftJoin, where) - reData := that.Db.Page(page, pageSize). - PageSelect(that.RouterString[1], leftJoin, columnStr, where) - - for _, v := range reData { - for k, _ := range v { - column := that.MakeCode.TableColumns[that.RouterString[1]][k] - if column == nil { - continue - } - - if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { - parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) - v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = "" - if parentC != nil { - v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value")) - } - } - - } - } - - that.Display(0, Map{"count": count, "data": reData}) - }, -} diff --git a/example/config/config.json b/example/config/config.json index 58216aa..5fb36fe 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -42,7 +42,7 @@ "4": "数据处理异常", "5": "数据结果异常" }, - "mode": 0, + "mode": 2, "port": "80", "sessionName": "HOTIME", "smsYzmTpt": "【乐呵呵旅游网】您正在进行身份验证,验证码{验证码},打死不要告诉别人哦!!!", diff --git a/example/main.go b/example/main.go index a19ef5f..7d611ee 100644 --- a/example/main.go +++ b/example/main.go @@ -18,6 +18,17 @@ func main() { //RESTfull接口适配 appIns.SetConnectListener(func(context *hotime.Context) bool { + if context.RouterString[0] == "admin" { + if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" { + return true + } + + if context.Session("id").Data == nil { + context.Display(2, "你还没有登录") + return false + } + } + //文件上传接口 if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {