diff options
author | Griffin Smith <grfn@gws.fyi> | 2021-12-20T01·26-0500 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2021-12-20T01·28+0000 |
commit | 9ea538beeaa9eedfb88c69719da385f51454d764 (patch) | |
tree | b96a40b7474459f0e7830f0bdc236828f020e492 /users | |
parent | 4643585e01e5dc68d6a815be23017ffe396a107a (diff) |
feat(grfn/bbbg): Move nav to page-global r/3315
Change-Id: I0a313d9df818fcbfeea5484123c1e7bcec439d66 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4509 Reviewed-by: grfn <grfn@gws.fyi> Autosubmit: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
Diffstat (limited to 'users')
-rw-r--r-- | users/grfn/bbbg/src/bbbg/handlers/core.clj | 40 | ||||
-rw-r--r-- | users/grfn/bbbg/src/bbbg/handlers/home.clj | 24 | ||||
-rw-r--r-- | users/grfn/bbbg/src/bbbg/web.clj | 2 |
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 |