aboutsummaryrefslogtreecommitdiff
path: root/cmd/server/handlers.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2022-09-17 11:41:20 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2022-09-17 11:41:20 -0400
commitccc26c3a0bb65ae2613e222c3ead7f6db377b483 (patch)
tree6124ae75f557fffe863134b967ee7c6bfcc87d3d /cmd/server/handlers.go
parentbf7d9c79cae53f64fcd04527248987bd4e7ca3c4 (diff)
downloadgo-website-ccc26c3a0bb65ae2613e222c3ead7f6db377b483.tar.gz
go-website-ccc26c3a0bb65ae2613e222c3ead7f6db377b483.tar.xz
More work on the editor and update the example site to utilize it.v0.0.18
Diffstat (limited to 'cmd/server/handlers.go')
-rw-r--r--cmd/server/handlers.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/cmd/server/handlers.go b/cmd/server/handlers.go
index 1711ae3..c44c19c 100644
--- a/cmd/server/handlers.go
+++ b/cmd/server/handlers.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"path/filepath"
+ "strings"
"github.com/gorilla/mux"
"riedstra.dev/mitch/go-website/page"
@@ -22,7 +23,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rtr.PathPrefix("/edit/").Handler(
a.RequiresLogin(http.StripPrefix("/edit/", http.HandlerFunc(a.SaveEditPage)))).Methods("POST")
- if a.redisPool != nil {
+ if a.redisPool != nil && !a.IsLoggedIn(r) {
rtr.PathPrefix(fmt.Sprintf("/%s/{tag}", a.FeedPrefix)).Handler(
rediscache.HandleWithParams(a.redisPool, a.RedisKey,
http.HandlerFunc(a.FeedHandler)))
@@ -45,9 +46,27 @@ func (a *App) PageHandler(w http.ResponseWriter, r *http.Request) {
u = "/index"
}
+ loggedIn := a.IsLoggedIn(r)
+
+ if u == "/dashboard" && loggedIn {
+ u = page.TemplateDirectory + "/dashboard"
+ }
+
+ // Render nothing inside of the template directory if we're not logged in
+ if strings.HasPrefix(u[1:], filepath.Clean(page.TemplateDirectory)) &&
+ !loggedIn {
+
+ page.Render4xx(w, r, map[string]interface{}{
+ "LoggedIn": loggedIn,
+ }, 404)
+ return
+ }
+
u = filepath.Join(".", u)
- page.RenderForPath(w, r, u)
+ page.RenderWithVars(w, r, u, map[string]interface{}{
+ "LoggedIn": loggedIn,
+ })
}
func (a *App) RebuildIndexHandler(w http.ResponseWriter, r *http.Request) {