Show login page

This commit is contained in:
Peter Stuifzand 2020-07-04 15:07:32 +02:00
parent 32c8f0cfa0
commit 0fa2756b1b
2 changed files with 20 additions and 1 deletions

View File

@ -619,7 +619,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}() }()
if !sess.LoggedIn { if !sess.LoggedIn {
http.Redirect(w, r, "/", http.StatusFound) http.Redirect(w, r, "/auth/login", http.StatusFound)
return return
} }

View File

@ -2,6 +2,8 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"log"
"net/http" "net/http"
"strings" "strings"
@ -39,6 +41,23 @@ func NewSearchHandler(searchIndex bleve.Index) (http.Handler, error) {
} }
func (s *searchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 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")) q := bleve.NewQueryStringQuery(r.URL.Query().Get("q"))
sr := bleve.NewSearchRequest(q) sr := bleve.NewSearchRequest(q)
results, err := s.searchIndex.Search(sr) results, err := s.searchIndex.Search(sr)