about summary refs log tree commit diff
path: root/users/grfn/bbbg
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-12-19T05·03-0500
committerclbot <clbot@tvl.fyi>2021-12-19T05·06+0000
commit732d1b733a989c5941cbb40ea4418b9c2f5ee129 (patch)
tree84dcfbf1f0ed29cb0d5434c37d156a07c183683c /users/grfn/bbbg
parentc6e0f64f452c7dffe7b12d5a45422785b4a7cb2b (diff)
feat(grfn/bbbg): Add a Sign Out button r/3300
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
Diffstat (limited to 'users/grfn/bbbg')
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/core.clj4
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/home.clj22
2 files changed, 21 insertions, 5 deletions
diff --git a/users/grfn/bbbg/src/bbbg/handlers/core.clj b/users/grfn/bbbg/src/bbbg/handlers/core.clj
index beadc198d376..3226a221ef81 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/core.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/core.clj
@@ -1,5 +1,6 @@
 (ns bbbg.handlers.core
   (:require
+   [bbbg.user :as user]
    [bbbg.views.flash :as flash]
    [hiccup.core :refer [html]]
    [ring.util.response :refer [content-type response]]))
@@ -31,6 +32,9 @@
       response
       (content-type "text/html")))
 
+(defn authenticated? [request]
+  (some? (get-in request [:session ::user/id])))
+
 (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 4b46675e4c34..00a96f2d87f6 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/home.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/home.clj
@@ -2,10 +2,10 @@
   (:require
    [bbbg.db.user :as db.user]
    [bbbg.discord.auth :as discord.auth]
-   [bbbg.handlers.core :refer [page-response]]
+   [bbbg.handlers.core :refer [page-response authenticated?]]
    [bbbg.user :as user]
    [bbbg.views.flash :as flash]
-   [compojure.core :refer [GET routes]]
+   [compojure.core :refer [GET POST routes]]
    [ring.util.response :refer [redirect]]
    [bbbg.discord :as discord]))
 
@@ -14,7 +14,11 @@
    [:ul
     [:li [:a {:href "/signup-forms"}
           "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"}
             "Sign In"]])]])
 
@@ -28,8 +32,16 @@
 (defn home-routes [{:keys [db] :as env}]
   (routes
    (GET "/" request
-     (let [authenticated? (some? (get-in request [:session ::user/id]))]
-       (page-response (home-page {:authenticated? authenticated?}))))
+     (page-response (home-page {:authenticated? (authenticated? request)})))
+
+   (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
      (let [token (get-in request [:oauth2/access-tokens :discord])]