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:
parent
c6e0f64f45
commit
732d1b733a
2 changed files with 21 additions and 5 deletions
|
@ -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"])
|
||||
|
|
|
@ -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])]
|
||||
|
|
Loading…
Reference in a new issue