about summary refs log tree commit diff
path: root/users/grfn/bbbg/src
diff options
context:
space:
mode:
Diffstat (limited to 'users/grfn/bbbg/src')
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/core.clj40
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/home.clj24
-rw-r--r--users/grfn/bbbg/src/bbbg/web.clj2
3 files changed, 39 insertions, 27 deletions
diff --git a/users/grfn/bbbg/src/bbbg/handlers/core.clj b/users/grfn/bbbg/src/bbbg/handlers/core.clj
index f93904e4ff32..37561c25e1a3 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/core.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/core.clj
@@ -5,6 +5,37 @@
    [hiccup.core :refer [html]]
    [ring.util.response :refer [content-type response]]))
 
+(def ^:dynamic *authenticated?* false)
+
+(defn authenticated? [request]
+  (some? (get-in request [:session ::user/id])))
+
+(defn wrap-auth-required [handler]
+  (fn [req]
+    (when (authenticated? req)
+      (handler req))))
+
+(defn wrap-dynamic-auth [handler]
+  (fn [req]
+    (binding [*authenticated?* (authenticated? req)]
+      (handler req))))
+
+(defn global-nav []
+  [:nav.global-nav
+   [:ul
+    (when *authenticated?*
+      [:li [:a {:href "/attendees"}
+            "Attendees"]])
+    [:li [:a {:href "/events"}
+          "Events"]]
+    (if authenticated?
+      [:li [:form {:method :post
+                   :action "/auth/sign-out"}
+            [:input {:type "submit"
+                     :value "Sign Out"}]]]
+      [:li [:a {:href "/auth/discord"}
+            "Sign In"]])]])
+
 (defn render-page [opts & body]
   (let [[{:keys [title]} body]
         (if (map? opts)
@@ -22,6 +53,7 @@
                :href "/main.css"}]]
       [:body
        [:div.content
+        (global-nav)
         (flash/render-flash)
         body]
        [:script {:src "https://cdnjs.cloudflare.com/ajax/libs/tarekraafat-autocomplete.js/10.2.6/autoComplete.js"}]
@@ -32,14 +64,6 @@
       response
       (content-type "text/html")))
 
-(defn authenticated? [request]
-  (some? (get-in request [:session ::user/id])))
-
-(defn wrap-auth-required [handler]
-  (fn [req]
-    (when (authenticated? req)
-      (handler req))))
-
 (comment
   (render-page
    [:h1 "hi"])
diff --git a/users/grfn/bbbg/src/bbbg/handlers/home.clj b/users/grfn/bbbg/src/bbbg/handlers/home.clj
index 81a968739718..8ca12687a1cf 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/home.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/home.clj
@@ -9,23 +9,10 @@
    [ring.util.response :refer [redirect]]
    [bbbg.discord :as discord]))
 
-(defn- home-page [{:keys [authenticated?]}]
-  [:nav.home-nav
-   [:ul
-    (when authenticated?
-      [:li [:a {:href "/attendees"}
-            "Attendees"]])
-    [:li [:a {:href "/events"}
-          "Events"]]
-    [:li [:a {:href "/signup-forms"}
-          "Event Signup Form"]]
-    (if authenticated?
-      [:li [:form {:method :post
-                   :action "/auth/sign-out"}
-            [:input {:type "submit"
-                     :value "Sign Out"}]]]
-      [:li [:a {:href "/auth/discord"}
-            "Sign In"]])]])
+(defn- home-page []
+  [:div.home-page
+   [:a {:href "/signup-forms"}
+    "Event Signup Form"]])
 
 (defn auth-failure []
   [:div.auth-failure
@@ -36,8 +23,7 @@
 
 (defn home-routes [{:keys [db] :as env}]
   (routes
-   (GET "/" request
-     (page-response (home-page {:authenticated? (authenticated? request)})))
+   (GET "/" [] (page-response (home-page)))
 
    (POST "/auth/sign-out" request
      (if (authenticated? request)
diff --git a/users/grfn/bbbg/src/bbbg/web.clj b/users/grfn/bbbg/src/bbbg/web.clj
index 4501043e2f5f..2419eb23b774 100644
--- a/users/grfn/bbbg/src/bbbg/web.clj
+++ b/users/grfn/bbbg/src/bbbg/web.clj
@@ -3,6 +3,7 @@
    [bbbg.discord.auth :as discord.auth :refer [wrap-discord-auth]]
    [bbbg.handlers.attendee-checks :as attendee-checks]
    [bbbg.handlers.attendees :as attendees]
+   [bbbg.handlers.core :refer [wrap-dynamic-auth]]
    [bbbg.handlers.events :as events]
    [bbbg.handlers.home :as home]
    [bbbg.handlers.signup-form :as signup-form]
@@ -82,6 +83,7 @@
 
 (defn middleware [app env]
   (-> app
+      wrap-dynamic-auth
       (wrap-discord-auth env)
       wrap-keyword-params
       wrap-params