about summary refs log tree commit diff
path: root/users/grfn/bbbg
diff options
context:
space:
mode:
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])]