Example #1
0
func renderEntriesList(entries []Entry) template.HTML {
	buf := &bytes.Buffer{}
	buf.WriteString(`
<div class="row" id="entries">`)
	for _, e := range entries {
		title := template.HTMLEscapeString(e.Title)
		content := template.HTMLEscapeString(e.Content)
		content = strings.Replace(content, "\n", "<br />\n", 0)
		fmt.Fprintf(buf, `
    <div class="panel panel-primary entry">
        <div class="entry-title">タイトル: <a href="/diary/entry/%d">%s</a></div>
        <div class="entry-content">
%s
        </div>
	`, e.ID, title, content)
		if e.Private {
			buf.WriteString(`<div class="text-danger entry-private">範囲: 友だち限定公開</div>`)
		}
		fmt.Fprintf(buf, `
        <div class="entry-created-at">更新日時: %s</div>
        <div class="entry-comments">コメント: %d件</div>
    </div>`,
			e.CreatedAt.Format("2006-01-02 15:04:05"), e.NumComments)
	}
	buf.WriteString(`</div>`)
	return template.HTML(buf.String())
}
Example #2
0
func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) //获取请求的方法
	if r.Method == "GET" {
		crutime := time.Now().Unix()
		h := md5.New()
		io.WriteString(h, strconv.FormatInt(crutime, 10))
		token := fmt.Sprintf("%x", h.Sum(nil))
		fmt.Println("token", token)
		t, _ := template.ParseFiles("login.gtpl")
		t.Execute(w, token)
	} else {
		//请求的是登陆数据,那么执行登陆的逻辑判断
		r.ParseForm()
		token := r.Form.Get("token")
		if token != "" {
			//验证 token 的合法性
		} else {
			//不存在 token 报错
		}
		fmt.Println("username length:", len(r.Form["username"][0]))
		fmt.Println("username:"******"username"))) //输出到服务器端
		fmt.Println("password:"******"password")))
		template.HTMLEscape(w, []byte(r.Form.Get("username"))) //输出到客户端
	}
}
func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method: ", r.Method)
	if r.Method == "GET" {
		cruTime := time.Now().Unix()
		h := md5.New()
		io.WriteString(h, strconv.FormatInt(cruTime, 10))
		token := fmt.Sprintf("%x", h.Sum(nil))

		t, _ := template.ParseFiles("04-02-03-duplicate-prevention.gtpl")
		t.Execute(w, token)

	} else {
		// log in request
		r.ParseForm()
		token := r.Form.Get("token")

		if token != "" {
			// check token validity
			fmt.Println("TODO: check if the token is valid: %s\n", token)
		} else {
			// give error if no token
			fmt.Println("TODO: handle error as token is not valid!")
		}

		fmt.Printf("Username length: %v\n", len(r.Form["username"][0]))
		fmt.Printf("Username       : %v\n", template.HTMLEscapeString(r.Form.Get("username")))
		fmt.Printf("password       : %v\n", template.HTMLEscapeString(r.Form.Get("password")))
		template.HTMLEscape(w, []byte(r.Form.Get("username")))
	}
}
Example #4
0
func handlerCreateAccount(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		giveFormTemplate("static/create_account.html", w)
	} else if r.Method == "POST" {
		r.ParseForm()
		email := string(template.HTMLEscapeString(r.Form.Get("email")))
		if !validEmail(email) {
			fmt.Fprintf(w, "Please input a valid email")
			return
		}
		username := string(template.HTMLEscapeString(r.Form.Get("username")))
		if username == "" {
			fmt.Fprintf(w, "Username can't be blank")
			return
		}
		password := r.Form.Get("password")
		if !validPassword(password) {
			fmt.Fprintln(w, "Given password does not comply with ",
				"given password directives")
			return
		}
		password = getSha512B64(r.Form.Get("password"))
		if err := AddUser(email, password, username); err != nil {
			fmt.Fprintf(w, "Mail or username already in use or %s\n", err)
			return
		}
		http.Redirect(w, r, "/created", http.StatusFound)
	}
}
Example #5
0
func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method)
	if r.Method == "GET" {
		crutime := time.Now().Unix()
		fmt.Println("crutime = ", crutime)
		h := md5.New()
		s := strconv.FormatInt(crutime, 10)
		fmt.Println("s = ", s)
		io.WriteString(h, s)
		fmt.Println("h's md5 = ", h.Sum(nil))
		token := fmt.Sprintf("%x", h.Sum(nil))
		t, _ := template.ParseFiles("login.gtpl")
		t.Execute(w, token)
	} else {
		r.ParseForm()
		token := r.Form.Get("token")
		if token != "" {
			fmt.Println("token is ", token)
		} else {
			fmt.Println("token is not exists ")
		}
		fmt.Println("username length:", len(r.Form["username"][0]))
		fmt.Println("username:"******"username")))
		fmt.Println("password:"******"password")))
		template.HTMLEscape(w, []byte(r.Form.Get("username")))
	}
}
Example #6
0
func (p *PageIndex) Sign(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		p.Body = "不支持这种请求方式: " + fmt.Sprintf("%v", r.Method)
		p.Template = "index/error.html"
		return
	}

	entry := NewGuestBook()
	entry.Name = p.POST["name"]
	entry.Message = p.POST["message"]

	if entry.Name == "" {
		entry.Name = "Some dummy who forgot a name"
	}
	if entry.Message == "" {
		entry.Message = "Some dummy who forgot a message."
	}

	entry.Name = template.HTMLEscapeString(entry.Name)
	entry.Message = template.HTMLEscapeString(entry.Message)

	mgo := Middleware.Get("db").(*helper.Mongo)
	coll := mgo.C(ColGuestBook)

	if err := coll.Insert(entry); err != nil {
		p.Body = "数据库错误:" + fmt.Sprintf("%v", err)
		p.Template = "index/error.html"
		return
	} else {
		http.Redirect(w, r, "/", http.StatusFound)
	}

}
Example #7
0
func (r *Result) MarshalJSON() ([]byte, error) {
	return json.Marshal(
		&map[string]string{
			"z": template.HTMLEscapeString(r.Z),
			"m": template.HTMLEscapeString(r.M),
			"p": template.HTMLEscapeString(r.P)})
}
Example #8
0
func rejectWhereEmpty(key string, solutions []map[string]rdf.Term) []map[string]interface{} {
	// TODO clean up this function; choose another name too..
	included := make([]map[string]interface{}, 1)
	for _, m := range solutions {
		if m[key] != nil {
			tm := make(map[string]interface{})
			for k, v := range m {
				term := v.Serialize(rdf.Turtle)
				if k != "g" && k != "p" && strings.HasPrefix(term, "<"+conf.BaseURI) {

					// URL without enclosing angle brackets
					link := strings.Trim(term, "<>")

					if conf.UI.FetchLiterals {
						link = fmt.Sprintf("<div class='relative'><a class=\"resource-link\" href='%v'>%v</a><div class=\"tooltip\"><strong>%s</strong><div class='literals'>...</div></div></div>",
							link, template.HTMLEscapeString(term), template.HTMLEscapeString(term))
					} else {
						link = fmt.Sprintf("<a href='%v'>%v</a>",
							link, template.HTMLEscapeString(term))
					}

					tm[k] = template.HTML(link)
				} else {
					if conf.Vocab.Enabled {
						tm[k] = prefixify(&conf.Vocab.Dict, term)
					} else {
						tm[k] = term
					}
				}
			}
			included = append(included, tm)
		}
	}
	return included
}
Example #9
0
File: web.go Project: kingfree/haut
func login(w ResponseWriter, r *Request) {
	Println("方法:", r.Method)
	if r.Method == "GET" {
		crutime := time.Now().Unix()
		h := md5.New()
		io.WriteString(h, strconv.FormatInt(crutime, 10))
		token := Sprintf("%x", h.Sum(nil))

		t, _ := template.ParseFiles("login.html")
		t.Execute(w, token)
	} else {
		r.ParseForm()
		token := r.Form.Get("token")
		if token != "" {
			Println("标识:", token)
			// 验证合法性
		} else {
			Println("标识:未获取")
			// 报错
		}
		Println(r)
		Println("用户名长度:", len(r.Form["username"][0]))
		Println("用户名:", template.HTMLEscapeString(r.Form.Get("username")))
		Println("密码:", template.HTMLEscapeString(r.Form.Get("password")))
		template.HTMLEscape(w, []byte(r.Form.Get("username")))
	}
}
Example #10
0
func renderCommentsOfFriends(comments []Comment) template.HTML {
	buf := &bytes.Buffer{}
	buf.WriteString(`
  <div class="col-md-4">
    <div>あなたの友だちのコメント</div>
    <div id="friend-comments">`)

	for _, c := range comments {
		cowner := getUser(c.UserID)
		eowner := getUser(c.EntryOwnerID)
		comment := c.Comment
		if len(comment) > 30 {
			comment = comment[:27] + "..."
		}
		fmt.Fprintf(buf, `
      <div class="friend-comment">
        <ul class="list-group">
          <li class="list-group-item comment-from-to"><a href="/profile/%s">%sさん</a>から<a href="/profile/%s">%sさん</a>へのコメント:</li>
          <li class="list-group-item comment-comment">%s</li>
          <li class="list-group-item comment-created-at">投稿時刻:%s</li>
        </ul>
      </div>`, cowner.AccountName, template.HTMLEscapeString(cowner.NickName), eowner.AccountName, template.HTMLEscapeString(eowner.NickName),
			template.HTMLEscapeString(comment), c.CreatedAt.Format("2006-01-02 15:04:05"))
	}
	buf.WriteString(`</div></div>`)
	return template.HTML(buf.String())
}
Example #11
0
func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Method", r.Method)

	if r.Method == "GET" {
		crutime := time.Now().Unix()
		h := md5.New()

		io.WriteString(h, strconv.FormatInt(crutime, 10))
		token := fmt.Sprintf("%x", h.Sum(nil))

		t, _ := template.ParseFiles("login.gtpl")

		t.Execute(w, token)
	} else {
		r.ParseForm()

		token := r.Form.Get("token")

		if token != "" {
			// check token validity
		} else {
			// give error if no token
		}

		fmt.Println("username length:", len(r.Form["username"][0]))
		fmt.Println("username:"******"username")))
		fmt.Println("password:"******"password")))

		template.HTMLEscape(w, []byte(r.Form.Get("username")))
	}
}
Example #12
0
func index(w http.ResponseWriter, r *http.Request, folder string) {
	r.ParseForm()
	fmt.Println(r.Form)
	fmt.Println("path", r.URL.Path)
	fmt.Println("scheme", r.URL.Scheme)
	fmt.Println(r.Form["url_long"])
	for k, v := range r.Form {
		fmt.Println("key:", k)
		fmt.Println("val:", strings.Join(v, ""))
	}

	fi, err := ListDir(folder)
	if err != nil {
		fmt.Println("Error", err)
	}
	var result = ""
	for _, f := range fi {
		//		d := "-"
		if f.IsDir() {
			continue
		}
		result += "<a href=/open/" + template.HTMLEscapeString(f.Name()) + ">" + template.HTMLEscapeString(f.Name()) + "</a><br>"
	}

	fmt.Fprint(w, result)
}
Example #13
0
func doLogin(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) //リクエストを取得するメソッド

	sess := globalSessions.SessionStart(w, r)
	r.ParseForm()

	if r.Method == "GET" {
		t, _ := template.ParseFiles("templates/login.tmpl.html")
		t.Execute(w, sess.Get("username"))
	} else {
		username := template.HTMLEscapeString(r.Form.Get("username"))
		token := r.Form.Get("token")
		if token != "" {
			//tokenの合法性を検証します。
		} else {
			//tokenが存在しなければエラーを出します。
		}

		sess.Set("username", username)

		// r.FormValue["username"]と書くことでr.ParseForm()を省略可能
		fmt.Println("username length:", len(r.Form["username"][0]))
		fmt.Println("username:"******"password:"******"password")))

		http.Redirect(w, r, "/", 302)
	}
}
Example #14
0
// printFunctionSourceLine prints a source line and the corresponding assembly.
func printFunctionSourceLine(w io.Writer, fn *node, assembly nodes, rpt *Report) {
	if len(assembly) == 0 {
		fmt.Fprintf(w,
			"<span class=line> %6d</span> <span class=nop>  %10s %10s %s </span>\n",
			fn.info.lineno,
			valueOrDot(fn.flat, rpt), valueOrDot(fn.cum, rpt),
			template.HTMLEscapeString(fn.info.name))
		return
	}

	fmt.Fprintf(w,
		"<span class=line> %6d</span> <span class=deadsrc>  %10s %10s %s </span>",
		fn.info.lineno,
		valueOrDot(fn.flat, rpt), valueOrDot(fn.cum, rpt),
		template.HTMLEscapeString(fn.info.name))
	fmt.Fprint(w, "<span class=asm>")
	for _, an := range assembly {
		var fileline string
		class := "disasmloc"
		if an.info.file != "" {
			fileline = fmt.Sprintf("%s:%d", template.HTMLEscapeString(an.info.file), an.info.lineno)
			if an.info.lineno != fn.info.lineno {
				class = "unimportant"
			}
		}
		fmt.Fprintf(w, " %8s %10s %10s %8x: %-48s <span class=%s>%s</span>\n", "",
			valueOrDot(an.flat, rpt), valueOrDot(an.cum, rpt),
			an.info.address,
			template.HTMLEscapeString(an.info.name),
			class,
			template.HTMLEscapeString(fileline))
	}
	fmt.Fprintln(w, "</span>")
}
Example #15
0
// Render renders the HTML element into its string representation.
// It also surfaces all initFuncs to the top and returns them.
func (s HTML) Render() (string, []func()) {
	var result string
	var initFuncs []func()
	if s.tag != "" {
		result = "<" + s.tag
		for _, v := range s.props {
			result += fmt.Sprintf(" %s=%q", v[0], template.HTMLEscapeString(v[1]))
		}
		var styles string
		for _, v := range s.styles {
			styles += fmt.Sprintf("%s:%s;", v[0], template.HTMLEscapeString(v[1]))
		}
		if styles != "" {
			result += fmt.Sprintf(" style=%q", styles)
		}
		if s.body == "" && len(s.elems) == 0 {
			result += "/"
		}
		result += ">"
	}
	for _, v := range s.elems {
		str, ifs := v.Render()
		result += str
		initFuncs = append(initFuncs, ifs...)
	}
	initFuncs = append(initFuncs, s.initFuncs...)
	result += template.HTMLEscapeString(s.body)
	if s.tag != "" && !(s.body == "" && len(s.elems) == 0) {
		result += "</" + s.tag + ">"
	}
	return result, initFuncs
}
Example #16
0
// printFunctionHeader prints a function header for a weblist report.
func printFunctionHeader(w io.Writer, name, path string, flatSum, cumSum int64, rpt *Report) {
	fmt.Fprintf(w, `<h1>%s</h1>%s
<pre onClick="pprof_toggle_asm()">
  Total:  %10s %10s (flat, cum) %s
`,
		template.HTMLEscapeString(name), template.HTMLEscapeString(path),
		rpt.formatValue(flatSum), rpt.formatValue(cumSum),
		percentage(cumSum, rpt.total))
}
Example #17
0
func sourceLinkFn(pdoc *doc.Package, pos doc.Pos, text string) htemp.HTML {
	text = htemp.HTMLEscapeString(text)
	if pos.Line == 0 {
		return htemp.HTML(text)
	}
	u := fmt.Sprintf(pdoc.LineFmt, pdoc.Files[pos.File].URL, pos.Line)
	u = htemp.HTMLEscapeString(u)
	return htemp.HTML(fmt.Sprintf(`<a href="%s">%s</a>`, u, text))
}
Example #18
0
// HomeHandler handles the HTTP request
func HomeHandler(a *App, w http.ResponseWriter, r *http.Request) error {
	switch r.Method {

	case "GET":
		err := tpl.ExecuteTemplate(w, "home", &page{"Home", "Welcome home.", nil})
		if err != nil {
			log.Fatalln("Couldn't render home page template", err)
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return err
		}
		return nil

	case "POST":
		// Get current time
		t := time.Now()

		err := r.ParseForm()
		if err != nil {
			panic(err)
			return err
		}

		fmt.Println("Time spent parsing form: ", time.Since(t))
		t = time.Now()

		query := &query{
			SiteURL:  template.HTMLEscapeString(r.Form.Get("SiteURL")),
			Keywords: template.HTMLEscapeString(r.Form.Get("Keywords")),
			Email:    r.Form.Get("Email"),
		}
		matches := query.Scrape()

		fmt.Println("Time spent scraping form: ", time.Since(t))
		t = time.Now()

		err = tpl.ExecuteTemplate(w, "preview", &page{"Matches", "Showing all matches.", matches})
		if err != nil {
			log.Fatalln("Couldn't render page after POSTing: ", err)
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return err
		}

		fmt.Println("Time spent rendering template: ", time.Since(t))
		t = time.Now()

		err = matches[0].Send(query.Email)
		if err != nil {
			log.Fatalln("Couldn't send email: ", err)
			return err
		}

		fmt.Println("Time spent sending email: ", time.Since(t))
		return nil
	}
	return nil
}
Example #19
0
func (self *NewQuestionHandler) Post() {
	self.TplNames = "sdc/new-question.html"

	flash := beego.NewFlash()
	tags := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("tags"))))

	if tags == "" {

		flash.Error("尚未设置标签,请设定正确的标签!")
		flash.Store(&self.Controller)
		return
	} else {

		uid, _ := self.GetSession("userid").(int64)
		sess_username, _ := self.GetSession("username").(string)
		qid_title := template.HTMLEscapeString(strings.TrimSpace(self.GetString("title")))
		qid_content := template.HTMLEscapeString(strings.TrimSpace(self.GetString("content")))

		if qid_title != "" && qid_content != "" {

			qs := new(model.Question)
			qs.Title = qid_title
			qs.Tags = tags
			qs.Content = qid_content
			qs.Uid = uid
			qs.Author = sess_username
			qs.Created = time.Now()
			qs.Updated = qs.Created

			if s, e := helper.GetBannerThumbnail(qid_content); e == nil {
				qs.Attachment = s
			}

			if thumbnails, thumbnailslarge, thumbnailsmedium, thumbnailssmall, e := helper.GetThumbnails(qid_content); e == nil {
				qs.Thumbnails = thumbnails
				qs.ThumbnailsLarge = thumbnailslarge
				qs.ThumbnailsMedium = thumbnailsmedium
				qs.ThumbnailsSmall = thumbnailssmall
			}

			if qts, _, err := model.PostQuestion(qs); err == nil {
				model.SetRecordforImageOnPost(qts.Id, uid)
				self.Redirect("/"+strconv.Itoa(int(qts.Id))+"/", 302)
			} else {

				flash.Error(fmt.Sprint(err))
				flash.Store(&self.Controller)
				return
			}
		} else {
			flash.Error("问题标题或内容为空!")
			flash.Store(&self.Controller)
			return
		}
	}
}
Example #20
0
// HTMLSnippet returns an HTML snippet representing this rule.
func (rule RecordingRule) HTMLSnippet(pathPrefix string) template.HTML {
	ruleExpr := rule.vector.String()
	return template.HTML(fmt.Sprintf(
		`<a href="%s">%s</a>%s = <a href="%s">%s</a>`,
		pathPrefix+strutil.GraphLinkForExpression(rule.name),
		rule.name,
		template.HTMLEscapeString(rule.labels.String()),
		pathPrefix+strutil.GraphLinkForExpression(ruleExpr),
		template.HTMLEscapeString(ruleExpr)))
}
Example #21
0
func (field *TextField) Render(class string, attrs []string) template.HTML {
	attrsStr := ""
	if len(attrs) > 0 {
		for _, attr := range attrs {
			attrsStr += " " + template.HTMLEscapeString(attr)
		}
	}
	field.value = template.HTMLEscapeString(field.value)
	return template.HTML(fmt.Sprintf(`<input type="text" class="%s" value="%s" name=%q id=%q%s>`, class, field.value, field.name, field.name, attrsStr))
}
Example #22
0
func (pdoc *tdoc) SourceLink(pos doc.Pos, text string, textOnlyOK bool) htemp.HTML {
	if pos.Line == 0 || pdoc.LineFmt == "" || pdoc.Files[pos.File].URL == "" {
		if textOnlyOK {
			return htemp.HTML(htemp.HTMLEscapeString(text))
		}
		return ""
	}
	return htemp.HTML(fmt.Sprintf(`<a title="View Source" href="%s">%s</a>`,
		htemp.HTMLEscapeString(fmt.Sprintf(pdoc.LineFmt, pdoc.Files[pos.File].URL, pos.Line)),
		htemp.HTMLEscapeString(text)))
}
Example #23
0
func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method)
	if r.Method == "GET" {
		t, _ := template.ParseFiles("login.gtpl")
		t.Execute(w, nil)
	} else {
		r.ParseForm()
		fmt.Println("username:"******"username"]))
		fmt.Println("password:"******"password"]))
	}
}
Example #24
0
func (u UserInfo) HTML() template.HTML {
	html := template.HTMLEscapeString(u.Name)

	if u.Email != "" {
		html += fmt.Sprintf(` <%s>`, template.HTMLEscapeString(u.Email))
	}

	if u.URL != "" {
		url := template.HTMLEscapeString(u.URL)
		html += fmt.Sprintf(` (<a href="%s">%s</a>)`, url, url)
	}

	return template.HTML(html)
}
Example #25
0
func (pdoc *tdoc) SourceLink(pos doc.Pos, text, anchor string) htemp.HTML {
	text = htemp.HTMLEscapeString(text)
	if pos.Line == 0 || pdoc.LineFmt == "" || pdoc.Files[pos.File].URL == "" {
		return htemp.HTML(text)
	}
	var u string
	if anchor != "" && strings.HasPrefix(pdoc.Files[pos.File].URL, "/") {
		u = fmt.Sprintf("%s#%s", pdoc.Files[pos.File].URL, anchor)
	} else {
		u = fmt.Sprintf(pdoc.LineFmt, pdoc.Files[pos.File].URL, pos.Line)
	}
	u = htemp.HTMLEscapeString(u)
	return htemp.HTML(fmt.Sprintf(`<a href="%s">%s</a>`, u, text))
}
Example #26
0
func writeHTML(ctx data.Entry, dirname string) error {
	filename := strings.Replace(template.URLQueryEscaper(ctx.Translations[0].Language+"_"+ctx.Translations[0].Words[0].Written+".html"), "%", "X", -1)

	file, err := os.Create(filename)
	defer file.Close()
	if err != nil {
		return err
	}

	showme := struct {
		Title string
		Body  template.HTML
	}{
		ctx.Translations[0].Words[0].Written + ": " + ctx.Wordtype,
		template.HTML(""),
	}

	for _, translation := range ctx.Translations {
		showme.Body += template.HTML("<div class=\"word\"><div id=\"" + translation.Language + "\" class=\"wordheader\">" + translation.Language + "</div>\n<div class=\"definitions\">")
		for _, word := range translation.Words {
			showme.Body += template.HTML("<div class=\"definition\">" +
				template.HTMLEscapeString(word.Written))
			for _, sw := range word.Sources {
				showme.Body += template.HTML("<span class=\"source\">" +
					template.HTMLEscapeString(sw) + "</span>")
			}

			showme.Body += template.HTML("</div>")
			references = append(references, [3]string{translation.Language, word.Written, filename})
			found := false
			firstletter, _ := utf8.DecodeRuneInString(strings.ToLower(word.Written))
			for _, letter := range alphabet {
				if firstletter == letter {
					found = true
				}
			}
			if !found {
				alphabet = append(alphabet, firstletter)
			}
		}
		showme.Body += template.HTML("</div></div>")
	}

	err = tmpl.Execute(file, showme)
	if err != nil {
		return err
	}

	return nil
}
Example #27
0
func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) //获取请求的方法
	if r.Method == "GET" {
		t, _ := template.ParseFiles("login.gtpl")
		t.Execute(w, nil)
	} else {
		r.ParseForm()
		//请求的是登陆数据,那么执行登陆的逻辑判断
		fmt.Println("username:"******"username")))
		fmt.Println("username:"******"password")))
		template.HTMLEscape(w, []byte(r.Form.Get("username")))

	}
}
Example #28
0
// NewUserHandler just registers a new user in the database.
func NewUserHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	r.ParseForm()
	user := &User{
		Name:        template.HTMLEscapeString(r.Form.Get("Name")),
		Email:       template.HTMLEscapeString(r.Form.Get("Email")),
		DateCreated: time.Now(),
	}

	// No point in dealing with errors unless we buffer our response
	_ = NewUser(user)
	err := Template.ExecuteTemplate(w, "signup", user)
	if err != nil {
		log.Printf("Error rendering email signup page: %s\n", err.Error())
	}
}
Example #29
0
func (c *Context) graph(v interface{}, unit string, filter bool) (val interface{}) {
	defer func() {
		if p := recover(); p != nil {
			err := fmt.Errorf("panic rendering graph %v", p)
			c.addError(err)
			slog.Error(err)
			val = err.Error()
		}
	}()
	res, exprText, err := c.eval(v, filter, true, 1000)
	if err != nil {
		c.addError(err)
		return err.Error()
	}
	var buf bytes.Buffer
	const width = 800
	const height = 600
	footerHTML := fmt.Sprintf(`<p><small>Query: %s<br>Time: %s</small></p>`,
		template.HTMLEscapeString(exprText),
		c.runHistory.Start.Format(time.RFC3339))
	if c.IsEmail {
		err := c.schedule.ExprPNG(nil, &buf, width, height, unit, res)
		if err != nil {
			c.addError(err)
			return err.Error()
		}
		name := fmt.Sprintf("%d.png", len(c.Attachments)+1)
		c.Attachments = append(c.Attachments, &models.Attachment{
			Data:        buf.Bytes(),
			Filename:    name,
			ContentType: "image/png",
		})
		return template.HTML(fmt.Sprintf(`<a href="%s" style="text-decoration: none"><img alt="%s" src="cid:%s" /></a>%s`,
			c.GraphLink(exprText),
			template.HTMLEscapeString(fmt.Sprint(v)),
			name,
			footerHTML,
		))
	}
	buf.WriteString(fmt.Sprintf(`<a href="%s" style="text-decoration: none">`, c.GraphLink(exprText)))
	if err := c.schedule.ExprSVG(nil, &buf, width, height, unit, res); err != nil {
		c.addError(err)
		return err.Error()
	}
	buf.WriteString(`</a>`)
	buf.WriteString(footerHTML)
	return template.HTML(buf.String())
}
Example #30
0
func Html_link(url string, text string, more_params ...interface{}) string {
	params := make(map[string]string)
	params["href"] = url
	params["title"] = text
	html := "<a " + paramsAsString(params_merge(params, more_params)) + ">" + template.HTMLEscapeString(text) + "</a>"
	return html
}