From 77594fd2b62e4ea3e6a55fed2dabcce50e618bd3 Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 10 May 2025 10:59:30 +0200 Subject: Add oauth for admin interface --- src/chef/pages/admin.clj | 11 ++++++----- src/chef/pages/home.clj | 15 ++++++++++----- src/chef/pages/utils.clj | 8 -------- 3 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 src/chef/pages/utils.clj (limited to 'src/chef/pages') diff --git a/src/chef/pages/admin.clj b/src/chef/pages/admin.clj index c06b475..3e2b0a1 100644 --- a/src/chef/pages/admin.clj +++ b/src/chef/pages/admin.clj @@ -1,10 +1,11 @@ (ns chef.pages.admin - (:require [chef.pages.utils :as cputils] + (:require [chef.utils :as cutils] [hiccup2.core :as html] [ring.util.response :as ruresp])) (defn handler [req] - (-> (cputils/gen-page "chef - Dashboard" [:i "Coming soon..."]) - html/html - str - ruresp/response)) + (cutils/auth-only req + (-> (cutils/gen-page "chef - Dashboard" [:i "Coming soon..."]) + html/html + str + ruresp/response))) diff --git a/src/chef/pages/home.clj b/src/chef/pages/home.clj index 725ba2b..84f643f 100644 --- a/src/chef/pages/home.clj +++ b/src/chef/pages/home.clj @@ -1,10 +1,15 @@ (ns chef.pages.home (:require [hiccup2.core :as html] [ring.util.response :as ruresp] - [chef.pages.utils :as cputils])) + [chef.utils :as cutils] + [ring.middleware.session :as rmsession])) (defn handler [req] - (-> (cputils/gen-page "chef" [:i "Coming soon..."]) - html/html - str - ruresp/response)) + (let [access-token (get-in req [:oauth2/access-tokens :auth]) + resp (-> (cutils/gen-page "chef" [:i "Coming soon..."]) + html/html + str + ruresp/response)] + (if (some? access-token) + (assoc resp :session (assoc (:session req) :oauth-token access-token)) + resp))) diff --git a/src/chef/pages/utils.clj b/src/chef/pages/utils.clj deleted file mode 100644 index 72d33fd..0000000 --- a/src/chef/pages/utils.clj +++ /dev/null @@ -1,8 +0,0 @@ -(ns chef.pages.utils) - -(defn gen-page [title & content] - [:html - [:head - [:meta {:name "viewport" :content "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"}] - [:title title]] - (apply conj [:body] content [[:script {:src "/static/htmx.js"}]])]) -- cgit v1.2.3