From 5348baeb2ba131451e2e31f985198f8928c526e6 Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 30 May 2018 23:28:39 +0800 Subject: [PATCH] tce add base.html --- src/contexts/ctx.go | 4 +- src/contexts/web/web.go | 94 ++++++++++------- usr/template/common/base.html | 35 +++++++ usr/template/common/login.html | 54 +++++----- usr/template/upload.html | 183 +++++++++++++-------------------- 5 files changed, 196 insertions(+), 174 deletions(-) create mode 100644 usr/template/common/base.html diff --git a/src/contexts/ctx.go b/src/contexts/ctx.go index e117033c..be1429b1 100644 --- a/src/contexts/ctx.go +++ b/src/contexts/ctx.go @@ -2382,7 +2382,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心", } if len(arg) > 3 { for _, v := range group.Commands[item].Shares[arg[2]] { - if arg[3] == v { + match, e := regexp.MatchString(v, arg[3]) + m.Assert(e) + if match { m.Echo("ok") return } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 2c9696e5..4b503b88 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -602,17 +602,16 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", r := m.Data["request"].(*http.Request) // {{{ w := m.Data["response"].(http.ResponseWriter) - m.Option("message", "") if !m.Options("file") { m.Option("file", m.Cap("directory")) } - dir := m.Option("file") if !m.Options("username") { m.Option("username", "") } m.Option("right", "") + m.Option("message", "") aaa := m.Find("aaa").Cmd("login", m.Option("sessid")) if aaa.Result(0) == "error: " { m.Option("sessid", "") @@ -620,15 +619,20 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } else { m.Option("username", aaa.Result(0)) msg := m.Spawn(m.Target()) - msg.Cmd("right", "check", aaa.Cap("group"), "command", "/upload", "file", dir) + msg.Cmd("right", "check", aaa.Cap("group"), "command", "/upload", "file", m.Option("file")) if msg.Result(0) == "ok" { m.Option("right", aaa.Cap("group")) } else { - m.Option("message", "your do not have the right of", dir) + m.Option("message", "your do not have the right of", m.Option("file")) } } if m.Option("method") == "POST" { + if !m.Options("right") { + m.Echo("you do not have the rightt, please contact manager!") + return + } + if m.Options("notshareto") { msg := m.Spawn(m.Target()) msg.Cmd("right", "del", m.Option("notshareto"), "command", "/upload", "file", m.Option("sharefile")) @@ -641,7 +645,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", m.Append("link", "hello") return } else if m.Options("content") { - name := path.Join(dir, m.Option("filename")) + name := path.Join(m.Option("file"), m.Option("filename")) if _, e := os.Stat(name); e != nil { f, e := os.Create(name) m.Assert(e) @@ -657,7 +661,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", file, header, e := r.FormFile("file") m.Assert(e) - name := path.Join(dir, header.Filename) + name := path.Join(m.Option("file"), header.Filename) if _, e := os.Stat(name); e != nil { f, e := os.Create(name) @@ -672,6 +676,19 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } } + if !m.Options("right") { + w.Header().Add("Content-Type", "text/html") + tmpl := template.Must(template.Must(template.ParseGlob(m.Conf("template_dir") + "/common/*.html")).ParseGlob(m.Conf("template_dir") + "upload.html")) + m.Assert(tmpl) + + tmpl.ExecuteTemplate(w, "head", m.Meta) + tmpl.ExecuteTemplate(w, "login", m.Meta) + m.Option("message", "your do not have the right, please contact manager") + tmpl.ExecuteTemplate(w, "message", m.Meta) + tmpl.ExecuteTemplate(w, "tail", m.Meta) + return + } + file := m.Option("file") s, e := os.Stat(file) if m.Assert(e); !s.IsDir() { @@ -736,46 +753,41 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", m.Assert(tmpl) tmpl.ExecuteTemplate(w, "head", m.Meta) - if m.Options("right") { - tmpl.ExecuteTemplate(w, "userinfo", m.Meta) + tmpl.ExecuteTemplate(w, "userinfo", m.Meta) - msg := m.Spawn(m.Target()) + msg := m.Spawn(m.Target()) - index := msg.Target().Index - if index != nil && index[m.Option("right")] != nil { - for k, v := range index[m.Option("right")].Index { - // for k, v := range index { - for i, j := range v.Commands { - for v, n := range j.Shares { - for _, nn := range n { - match, e := regexp.MatchString(nn, dir) - m.Log("fuck", nil, "why %s %s", nn, dir) - m.Assert(e) - if match { - msg.Add("append", "group", k) - msg.Add("append", "command", i) - msg.Add("append", "argument", v) - msg.Add("append", "value", nn) - msg.Add("append", "delete", "delete") - } + index := msg.Target().Index + if index != nil && index[m.Option("right")] != nil { + for k, v := range index[m.Option("right")].Index { + // for k, v := range index { + for i, j := range v.Commands { + for v, n := range j.Shares { + for _, nn := range n { + match, e := regexp.MatchString(nn, m.Option("file")) + m.Log("fuck", nil, "why %s %s", nn, m.Option("file")) + m.Assert(e) + if match { + msg.Add("append", "group", k) + msg.Add("append", "command", i) + msg.Add("append", "argument", v) + msg.Add("append", "value", nn) + msg.Add("append", "delete", "delete") } } } } } - - tmpl.ExecuteTemplate(w, "share", msg.Meta) - - tmpl.ExecuteTemplate(w, "upload", m.Meta) - } else { - tmpl.ExecuteTemplate(w, "login", m.Meta) } + tmpl.ExecuteTemplate(w, "share", msg.Meta) + tmpl.ExecuteTemplate(w, "upload", m.Meta) + switch m.Option("cmd") { case "git": - branch := m.Find("nfs").Cmd("git", "-C", dir, "branch") + branch := m.Find("nfs").Cmd("git", "-C", m.Option("file"), "branch") m.Option("branch", branch.Result(0)) - status := m.Find("nfs").Cmd("git", "-C", dir, "status") + status := m.Find("nfs").Cmd("git", "-C", m.Option("file"), "status") m.Option("status", status.Result(0)) tmpl.ExecuteTemplate(w, "git", m.Meta) } @@ -785,9 +797,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } tmpl.ExecuteTemplate(w, "list", m.Meta) - if m.Options("right") { - tmpl.ExecuteTemplate(w, "create", m.Meta) - } + tmpl.ExecuteTemplate(w, "create", m.Meta) tmpl.ExecuteTemplate(w, "tail", m.Meta) delete(m.Meta, "result") delete(m.Meta, "append") @@ -899,6 +909,16 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", msg.Cmd("get", "method", "POST", "evaluating_add/", "questions", qs) m.Add("append", "hi", "hello") }}, + "/demo": &ctx.Command{Name: "/demo", Help: "应用示例", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { + w := m.Data["response"].(http.ResponseWriter) + + w.Header().Add("Content-Type", "text/html") + tmpl := template.Must(template.ParseGlob(m.Conf("template_dir") + "/common/*.html")) + m.Assert(tmpl) + + tmpl.ExecuteTemplate(w, "head", m.Meta) + tmpl.ExecuteTemplate(w, "tail", m.Meta) + }}, }, } diff --git a/usr/template/common/base.html b/usr/template/common/base.html new file mode 100644 index 00000000..b1d1b79f --- /dev/null +++ b/usr/template/common/base.html @@ -0,0 +1,35 @@ +{{define "head"}} + + + + + + + +{{end}} + +{{define "message"}} +
message +
{{index . "message"}}
+
+{{end}} + +{{define "tail"}} + + +{{end}} diff --git a/usr/template/common/login.html b/usr/template/common/login.html index 31981aae..31043e1c 100644 --- a/usr/template/common/login.html +++ b/usr/template/common/login.html @@ -43,34 +43,34 @@ - - {{range .append}} - - {{end}} - - - {{range .append}} - - {{end}} - - - {{$meta := .}} - {{if .append}} - {{$first := index .append 0}} - {{range $i, $k := index . $first}} - - {{range $key := index $meta "append"}} - - {{end}} - + + {{range .append}} + + {{end}} + + + {{range .append}} + + {{end}} + + + {{$meta := .}} + {{if .append}} + {{$first := index .append 0}} + {{range $i, $k := index . $first}} + + {{range $key := index $meta "append"}} + + {{end}} + + {{end}} {{end}} - {{end}}
{{.}}
- {{if eq $key "delete"}} - - {{else}} - {{index $meta $key $i}} - {{end}} -
{{.}}
+ {{if eq $key "delete"}} + + {{else}} + {{index $meta $key $i}} + {{end}} +
- - {{$meta := .}} - {{if .append}} - {{$first := index .append 0}} - {{range $i, $k := index . $first}} - - {{range $key := index $meta "append"}} - {{if eq $key "name"}} - - {{index $meta $key $i}} - - {{else if eq $key "path"}} - {{else}} - - {{index $meta $key $i}} - - {{end}} - {{end}} - - {{end}} - {{end}} - - -{{end}} - -{{define "create"}} -
create -
- - - -
filename:
content:
-
-
-{{end}} - -{{define "tail"}} - - +{{end}} + +{{define "create"}} +
create +
+ + + +
filename:
content:
+
+
{{end}}