diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-07-14 01:24:40 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-07-14 01:24:40 +0100 |
| commit | 08a3fb8a2b0281c3c329b33215ec7f8866add606 (patch) | |
| tree | ff8a5413449ea198bc063bf0099fc025ea49c82b /web/mux.go | |
| parent | 684787bcb72aece2aa914597a3bc8788432e66f7 (diff) | |
Add authentication and ability to change host
Diffstat (limited to 'web/mux.go')
| -rw-r--r-- | web/mux.go | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -3,21 +3,28 @@ package web import ( "net/http" + "github.com/LMBishop/scrapbook/pkg/auth" "github.com/LMBishop/scrapbook/pkg/config" "github.com/LMBishop/scrapbook/pkg/index" "github.com/LMBishop/scrapbook/web/command/handler" + "github.com/LMBishop/scrapbook/web/command/middleware" ) -func NewMux(cfg *config.MainConfig, siteIndex *index.SiteIndex) *http.ServeMux { +func NewMux(cfg *config.MainConfig, siteIndex *index.SiteIndex, authenticator *auth.Authenticator) *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("GET /", handler.GetHome(cfg, siteIndex)) - mux.HandleFunc("GET /create", handler.GetCreate()) - mux.HandleFunc("POST /create", handler.PostCreate(cfg, siteIndex)) - mux.HandleFunc("GET /site/{site}/", handler.GetSite(cfg, siteIndex)) - mux.HandleFunc("GET /site/{site}/upload", handler.GetUpload(siteIndex)) - mux.HandleFunc("POST /site/{site}/upload", handler.PostUpload(cfg, siteIndex)) - mux.HandleFunc("GET /site/{site}/flags", handler.GetFlags(siteIndex)) - mux.HandleFunc("POST /site/{site}/flags", handler.PostFlags(cfg, siteIndex)) + mux.HandleFunc("GET /authenticate", handler.GetAuthenticate()) + mux.HandleFunc("POST /authenticate", handler.PostAuthenticate(cfg, authenticator)) + + mux.HandleFunc("GET /", middleware.MustAuthenticate(authenticator, handler.GetHome(cfg, siteIndex))) + mux.HandleFunc("GET /create", middleware.MustAuthenticate(authenticator, handler.GetCreate())) + mux.HandleFunc("POST /create", middleware.MustAuthenticate(authenticator, handler.PostCreate(cfg, siteIndex))) + mux.HandleFunc("GET /site/{site}/", middleware.MustAuthenticate(authenticator, handler.GetSite(cfg, siteIndex))) + mux.HandleFunc("GET /site/{site}/upload", middleware.MustAuthenticate(authenticator, handler.GetUpload(siteIndex))) + mux.HandleFunc("POST /site/{site}/upload", middleware.MustAuthenticate(authenticator, handler.PostUpload(cfg, siteIndex))) + mux.HandleFunc("GET /site/{site}/flags", middleware.MustAuthenticate(authenticator, handler.GetFlags(siteIndex))) + mux.HandleFunc("POST /site/{site}/flags", middleware.MustAuthenticate(authenticator, handler.PostFlags(cfg, siteIndex))) + mux.HandleFunc("GET /site/{site}/host", middleware.MustAuthenticate(authenticator, handler.GetHost(siteIndex))) + mux.HandleFunc("POST /site/{site}/host", middleware.MustAuthenticate(authenticator, handler.PostHost(cfg, siteIndex))) return mux } |
