Check if we are logged in

This commit is contained in:
Peter Stuifzand 2019-02-05 21:22:16 +01:00
parent f70d1ccc05
commit 8e2dd0993a

17
main.go
View File

@ -190,6 +190,11 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
defer sess.Flush() defer sess.Flush()
if !sess.LoggedIn {
http.Redirect(w, r, "/", http.StatusFound)
return
}
r.ParseForm() r.ParseForm()
page := r.URL.Path[9:] page := r.URL.Path[9:]
if page == "" { if page == "" {
@ -203,7 +208,7 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
funcs := template.FuncMap{ 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") 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() defer sess.Flush()
if !sess.LoggedIn {
http.Redirect(w, r, "/", http.StatusFound)
return
}
r.ParseForm() r.ParseForm()
page := r.PostForm.Get("p") page := r.PostForm.Get("p")
summary := r.PostForm.Get("summary") summary := r.PostForm.Get("summary")
@ -252,6 +262,11 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
defer sess.Flush() defer sess.Flush()
if !sess.LoggedIn {
http.Redirect(w, r, "/", http.StatusFound)
return
}
page := r.URL.Path[6:] page := r.URL.Path[6:]
if page == "" { if page == "" {
page = "Home" page = "Home"