| 1 |
package app
|
| 2 |
|
| 3 |
import "net/http"
|
| 4 |
|
| 5 |
// Wrapping helpers: every app route gets CSRF protection; auth/internal add
|
| 6 |
// session loading and the appropriate access guard.
|
| 7 |
func (a *App) pub(h http.HandlerFunc) http.Handler {
|
| 8 |
return a.csrf(h)
|
| 9 |
}
|
| 10 |
func (a *App) auth(h http.HandlerFunc) http.Handler {
|
| 11 |
return a.csrf(a.load(a.requireAuth(h)))
|
| 12 |
}
|
| 13 |
func (a *App) internal(h http.HandlerFunc) http.Handler {
|
| 14 |
return a.csrf(a.load(a.requireInternal(h)))
|
| 15 |
}
|
| 16 |
|
| 17 |
// Routes mounts the authenticated application routes onto an existing mux.
|
| 18 |
// The public demo (/, /api/analyze) is registered separately by main.go.
|
| 19 |
func (a *App) Routes(mux *http.ServeMux) {
|
| 20 |
mux.Handle("GET /login", a.pub(a.handleLoginForm))
|
| 21 |
mux.Handle("POST /login", a.pub(a.handleLogin))
|
| 22 |
mux.Handle("POST /logout", a.pub(a.handleLogout))
|
| 23 |
mux.Handle("GET /forgot", a.pub(a.handleForgotForm))
|
| 24 |
mux.Handle("POST /forgot", a.pub(a.handleForgot))
|
| 25 |
mux.Handle("GET /set-password", a.pub(a.handleSetPasswordForm))
|
| 26 |
mux.Handle("POST /set-password", a.pub(a.handleSetPassword))
|
| 27 |
|
| 28 |
mux.Handle("GET /app", a.auth(a.handleApp))
|
| 29 |
mux.Handle("POST /app/analyze", a.auth(a.handleAppAnalyze))
|
| 30 |
mux.Handle("GET /app/bom/{id}", a.auth(a.handleBOM))
|
| 31 |
|
| 32 |
mux.Handle("GET /admin", a.internal(a.handleAdmin))
|
| 33 |
mux.Handle("GET /admin/catalog", a.internal(a.handleCatalog))
|
| 34 |
mux.Handle("POST /admin/catalog", a.internal(a.handleCatalogSave))
|
| 35 |
mux.Handle("POST /admin/catalog/delete", a.internal(a.handleCatalogDelete))
|
| 36 |
mux.Handle("POST /admin/catalog/seed", a.internal(a.handleCatalogSeed))
|
| 37 |
mux.Handle("GET /admin/subscribers", a.internal(a.handleSubscribers))
|
| 38 |
mux.Handle("POST /admin/subscribers", a.internal(a.handleSubscriberCreate))
|
| 39 |
mux.Handle("POST /admin/users", a.internal(a.handleUserCreate))
|
| 40 |
mux.Handle("GET /admin/boms", a.internal(a.handleBOMs))
|
| 41 |
}
|