Require login to create events when auth is enabled
Gate the home page and POST /events behind auth. Also add sqlite3 CLI to the Docker image for DB inspection, and gitignore test.db files. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,3 +2,6 @@ bbq
|
|||||||
bbq.db
|
bbq.db
|
||||||
bbq.db-shm
|
bbq.db-shm
|
||||||
bbq.db-wal
|
bbq.db-wal
|
||||||
|
test.db
|
||||||
|
test.db-shm
|
||||||
|
test.db-wal
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ COPY . .
|
|||||||
RUN CGO_ENABLED=1 go build -o /bbq .
|
RUN CGO_ENABLED=1 go build -o /bbq .
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates sqlite3 && rm -rf /var/lib/apt/lists/*
|
||||||
COPY --from=build /bbq /usr/local/bin/bbq
|
COPY --from=build /bbq /usr/local/bin/bbq
|
||||||
VOLUME /data
|
VOLUME /data
|
||||||
ENV BBQ_DB=/data/bbq.db
|
ENV BBQ_DB=/data/bbq.db
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ func randomSlug() string {
|
|||||||
// --- Home / Create Event ---
|
// --- Home / Create Event ---
|
||||||
|
|
||||||
func (s *Server) handleHome(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleHome(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if s.features.Auth && s.currentUser(r) == nil {
|
||||||
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
|
return
|
||||||
|
}
|
||||||
pageTmpl["home"].ExecuteTemplate(w, "layout", map[string]any{
|
pageTmpl["home"].ExecuteTemplate(w, "layout", map[string]any{
|
||||||
"User": s.currentUser(r),
|
"User": s.currentUser(r),
|
||||||
"AuthEnabled": s.features.Auth,
|
"AuthEnabled": s.features.Auth,
|
||||||
|
|||||||
@@ -174,7 +174,11 @@ func main() {
|
|||||||
|
|
||||||
// Home / create event
|
// Home / create event
|
||||||
r.Get("/", srv.handleHome)
|
r.Get("/", srv.handleHome)
|
||||||
r.Post("/events", srv.handleCreateEvent)
|
if features.Auth {
|
||||||
|
r.With(srv.requireAuth).Post("/events", srv.handleCreateEvent)
|
||||||
|
} else {
|
||||||
|
r.Post("/events", srv.handleCreateEvent)
|
||||||
|
}
|
||||||
|
|
||||||
// Guest event view
|
// Guest event view
|
||||||
r.Get("/e/{slug}", srv.handleEvent)
|
r.Get("/e/{slug}", srv.handleEvent)
|
||||||
|
|||||||
Reference in New Issue
Block a user