Esempio n. 1
0
func TestCSRFHandler(w http.ResponseWriter, r *http.Request) {
	templates_dir, dir_err := env.GetQindTemplatesDir()
	if dir_err != nil {
		http.Error(w, dir_err.Error(), http.StatusInternalServerError)
		return
	}
	token, token_err := validation.MakeFormToken(r, CSRF_FORM_TARGET)
	if token_err != nil {
		http.Error(w, token_err.Error(), http.StatusInternalServerError)
		return
	}
	t, t_err := template.ParseFiles(templates_dir + string(filepath.Separator) +
		"test" + string(filepath.Separator) + "csrf_test.html")
	if t_err != nil {
		http.Error(w, t_err.Error(), http.StatusInternalServerError)
		return
	}
	t.Execute(w, struct{ TokenFormKey, FormToken, FormTarget string }{env.TOKEN_FORM_KEY, token, CSRF_FORM_TARGET})
}
Esempio n. 2
0
func TestBasicHandler(w http.ResponseWriter, r *http.Request) {
	templates_dir, dir_err := env.GetQindTemplatesDir()
	if dir_err != nil {
		http.Error(w, dir_err.Error(), http.StatusInternalServerError)
		return
	}
	t, t_err := template.ParseFiles(templates_dir + string(filepath.Separator) +
		"test" + string(filepath.Separator) + "basic.html")
	if t_err != nil {
		http.Error(w, t_err.Error(), http.StatusInternalServerError)
		return
	}
	remote_addr, remote_addr_err := qind_net.ClientIP(r)
	if remote_addr_err != nil {
		http.Error(w, remote_addr_err.Error(), http.StatusInternalServerError)
		return
	}
	t.Execute(w, struct{ TestVar string }{remote_addr})
}