From 8e2dd0993a5dd95ed0c3c3ebbf70f62633484245 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Tue, 5 Feb 2019 21:22:16 +0100 Subject: [PATCH] Check if we are logged in --- main.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 7864031..60320e1 100644 --- a/main.go +++ b/main.go @@ -190,6 +190,11 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } defer sess.Flush() + if !sess.LoggedIn { + http.Redirect(w, r, "/", http.StatusFound) + return + } + r.ParseForm() page := r.URL.Path[9:] if page == "" { @@ -203,7 +208,7 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } funcs := template.FuncMap{ - "historyIndex": func(x int, history []Revision) int { return len(history) - x; }, + "historyIndex": func(x int, history []Revision) int { return len(history) - x }, } t, err := template.New("layout.html").Funcs(funcs).ParseFiles("templates/layout.html", "templates/history.html") @@ -234,6 +239,11 @@ func (h *saveHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } defer sess.Flush() + if !sess.LoggedIn { + http.Redirect(w, r, "/", http.StatusFound) + return + } + r.ParseForm() page := r.PostForm.Get("p") summary := r.PostForm.Get("summary") @@ -252,6 +262,11 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } defer sess.Flush() + if !sess.LoggedIn { + http.Redirect(w, r, "/", http.StatusFound) + return + } + page := r.URL.Path[6:] if page == "" { page = "Home"