Пример #1
0
func login(w http.ResponseWriter, r *http.Request) {
	user := ego.GetUser(r)
	if user.Username == "" {
		p := &Page{Title: "Restfish - login"}
		renderTemplate(w, "login", p)
	} else {
		http.Redirect(w, r, "/admin", http.StatusFound)
	}
}
Пример #2
0
func logReq(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		user := ego.GetUser(r)
		if user.Username != "" {
			log.Printf("session: " + user.Username)
		} else {
			log.Printf("session user empty")
			http.Redirect(w, r, "/", http.StatusFound)
			return
		}
		log.Printf(r.URL.Path + ":" + r.RemoteAddr)
		fn(w, r)
	}
}