Esempio n. 1
0
// Index page
func (c *AdminCtrl) Index(w http.ResponseWriter, r *http.Request) {
	s, err := session.Current(w, r)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	vm := &AdminViewModel{"Admin", s.UserID, s.Name}
	c.Templates.Lookup("admin.html").Execute(w, vm)
}
Esempio n. 2
0
// ServeHTTP authenticates the current session and then calls f(w, r).
func (f AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	s, err := session.Current(w, r)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	if s == nil {
		http.Redirect(w, r, "/login", 302)
	}

	f(w, r)
}