fix API endpoints which require account authorisation
This commit is contained in:
parent
090de0554b
commit
ad39e68cd6
2 changed files with 70 additions and 20 deletions
|
@ -20,20 +20,20 @@ func Handler(app *model.AppState) http.Handler {
|
|||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/login", loginHandler(app))
|
||||
mux.Handle("/logout", RequireAccount(app, logoutHandler(app)))
|
||||
mux.Handle("/logout", requireAccount(app, logoutHandler(app)))
|
||||
|
||||
mux.Handle("/register", registerAccountHandler(app))
|
||||
|
||||
mux.Handle("/account", RequireAccount(app, accountIndexHandler(app)))
|
||||
mux.Handle("/account/", RequireAccount(app, http.StripPrefix("/account", accountHandler(app))))
|
||||
mux.Handle("/account", requireAccount(app, accountIndexHandler(app)))
|
||||
mux.Handle("/account/", requireAccount(app, http.StripPrefix("/account", accountHandler(app))))
|
||||
|
||||
mux.Handle("/release/", RequireAccount(app, http.StripPrefix("/release", serveRelease(app))))
|
||||
mux.Handle("/artist/", RequireAccount(app, http.StripPrefix("/artist", serveArtist(app))))
|
||||
mux.Handle("/track/", RequireAccount(app, http.StripPrefix("/track", serveTrack(app))))
|
||||
mux.Handle("/release/", requireAccount(app, http.StripPrefix("/release", serveRelease(app))))
|
||||
mux.Handle("/artist/", requireAccount(app, http.StripPrefix("/artist", serveArtist(app))))
|
||||
mux.Handle("/track/", requireAccount(app, http.StripPrefix("/track", serveTrack(app))))
|
||||
|
||||
mux.Handle("/static/", http.StripPrefix("/static", staticHandler()))
|
||||
|
||||
mux.Handle("/", RequireAccount(app, AdminIndexHandler(app)))
|
||||
mux.Handle("/", requireAccount(app, AdminIndexHandler(app)))
|
||||
|
||||
// response wrapper to make sure a session cookie exists
|
||||
return enforceSession(app, mux)
|
||||
|
@ -381,7 +381,7 @@ func logoutHandler(app *model.AppState) http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
func RequireAccount(app *model.AppState, next http.Handler) http.HandlerFunc {
|
||||
func requireAccount(app *model.AppState, next http.Handler) http.HandlerFunc {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
if session.Account == nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue