From 0fa2756b1b6cf309b1ca9c0dc7da1f2cd2b9787e Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 4 Jul 2020 15:07:32 +0200 Subject: [PATCH] Show login page --- main.go | 2 +- search.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 2546c73..000acb6 100644 --- a/main.go +++ b/main.go @@ -619,7 +619,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { }() if !sess.LoggedIn { - http.Redirect(w, r, "/", http.StatusFound) + http.Redirect(w, r, "/auth/login", http.StatusFound) return } diff --git a/search.go b/search.go index 3a48074..a59cac5 100644 --- a/search.go +++ b/search.go @@ -2,6 +2,8 @@ package main import ( "encoding/json" + "fmt" + "log" "net/http" "strings" @@ -39,6 +41,23 @@ func NewSearchHandler(searchIndex bleve.Index) (http.Handler, error) { } func (s *searchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + + sess, err := NewSession(w, r) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + defer func() { + if err := sess.Flush(); err != nil { + log.Println(err) + } + }() + if !sess.LoggedIn { + fmt.Fprint(w, "{}") + return + } + q := bleve.NewQueryStringQuery(r.URL.Query().Get("q")) sr := bleve.NewSearchRequest(q) results, err := s.searchIndex.Search(sr)