login page

This commit is contained in:
Nazar Kanaev
2020-11-03 21:54:55 +00:00
parent 94d1659ad5
commit 0e2da62081
5 changed files with 104 additions and 3 deletions

View File

@@ -49,6 +49,14 @@ func (h Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusNotFound)
return
}
if h.requiresAuth() && !route.skipAuth {
if !userIsAuthenticated(req, h.Username, h.Password) {
rw.WriteHeader(http.StatusUnauthorized)
return
}
}
ctx := context.WithValue(req.Context(), ctxHandler, &h)
ctx = context.WithValue(ctx, ctxVars, vars)
route.handler(rw, req.WithContext(ctx))
@@ -137,6 +145,10 @@ func (h *Handler) startJobs() {
}
}
func (h Handler) requiresAuth() bool {
return h.Username != "" && h.Password != ""
}
func (h *Handler) fetchAllFeeds() {
h.log.Print("Refreshing all feeds")
for _, feed := range h.db.ListFeeds() {