feat(grfn/bbbg): Add a Sign Out button

Change-Id: Ia57a31101dc294dba54a4fde7af2b636288bd4cd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4411
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2021-12-19 00:03:45 -05:00 committed by clbot
parent c6e0f64f45
commit 732d1b733a
2 changed files with 21 additions and 5 deletions

View file

@ -1,5 +1,6 @@
(ns bbbg.handlers.core (ns bbbg.handlers.core
(:require (:require
[bbbg.user :as user]
[bbbg.views.flash :as flash] [bbbg.views.flash :as flash]
[hiccup.core :refer [html]] [hiccup.core :refer [html]]
[ring.util.response :refer [content-type response]])) [ring.util.response :refer [content-type response]]))
@ -31,6 +32,9 @@
response response
(content-type "text/html"))) (content-type "text/html")))
(defn authenticated? [request]
(some? (get-in request [:session ::user/id])))
(comment (comment
(render-page (render-page
[:h1 "hi"]) [:h1 "hi"])

View file

@ -2,10 +2,10 @@
(:require (:require
[bbbg.db.user :as db.user] [bbbg.db.user :as db.user]
[bbbg.discord.auth :as discord.auth] [bbbg.discord.auth :as discord.auth]
[bbbg.handlers.core :refer [page-response]] [bbbg.handlers.core :refer [page-response authenticated?]]
[bbbg.user :as user] [bbbg.user :as user]
[bbbg.views.flash :as flash] [bbbg.views.flash :as flash]
[compojure.core :refer [GET routes]] [compojure.core :refer [GET POST routes]]
[ring.util.response :refer [redirect]] [ring.util.response :refer [redirect]]
[bbbg.discord :as discord])) [bbbg.discord :as discord]))
@ -14,7 +14,11 @@
[:ul [:ul
[:li [:a {:href "/signup-forms"} [:li [:a {:href "/signup-forms"}
"Event Signup Form"]] "Event Signup Form"]]
(when-not authenticated? (if authenticated?
[:li [:form {:method :post
:action "/auth/sign-out"}
[:input {:type "submit"
:value "Sign Out"}]]]
[:li [:a {:href "/auth/discord"} [:li [:a {:href "/auth/discord"}
"Sign In"]])]]) "Sign In"]])]])
@ -28,8 +32,16 @@
(defn home-routes [{:keys [db] :as env}] (defn home-routes [{:keys [db] :as env}]
(routes (routes
(GET "/" request (GET "/" request
(let [authenticated? (some? (get-in request [:session ::user/id]))] (page-response (home-page {:authenticated? (authenticated? request)})))
(page-response (home-page {:authenticated? authenticated?}))))
(POST "/auth/sign-out" request
(if (authenticated? request)
(-> (redirect "/")
(update :session dissoc ::user/id)
(flash/add-flash
{:flash/message "Successfully Signed Out"
:flash/type :success}))
(redirect "/")))
(GET "/auth/success" request (GET "/auth/success" request
(let [token (get-in request [:oauth2/access-tokens :discord])] (let [token (get-in request [:oauth2/access-tokens :discord])]