Ejemplo n.º 1
0
// Template renders HTML templates
func Template(c web.C, w http.ResponseWriter, r *http.Request, templates []string, name string, data map[string]interface{}) error {
	funcMap := template.FuncMap{
		"formatTime": formatTime,
	}

	t, err := template.New("").Delims("{{{", "}}}").Funcs(funcMap).ParseFiles(templates...)
	if err != nil {
		return err
	}

	var loggedIn bool
	user, err := helpers.CurrentUser(c)

	if err != nil {
		loggedIn = false
	} else {
		loggedIn = true
	}

	data["CurrentUser"] = user
	data["UserSignedIn"] = loggedIn

	session := helpers.CurrentSession(c)
	data["Flashes"] = session.Flashes()
	session.Save(r, w)

	err = t.ExecuteTemplate(w, name, data)
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 2
0
// SignOut makes the user sign out
func SignOut(c web.C, w http.ResponseWriter, req *http.Request) {
	session := helpers.CurrentSession(c)
	session.Values = map[interface{}]interface{}{}
	session.Save(req, w)
	http.Redirect(w, req, "/", http.StatusFound)
}