diff --git a/src/clj/cat/handler.clj b/src/clj/cat/handler.clj
index cc6d3c3..e42c95b 100644
--- a/src/clj/cat/handler.clj
+++ b/src/clj/cat/handler.clj
@@ -2,7 +2,7 @@
(:require [cat.middleware :as middleware]
[cat.layout :refer [error-page]]
[cat.routes.home :refer [home-routes]]
- [cat.routes.oauth :refer [oauth-routes]]
+ [cat.routes.oauth :refer [oauth-routes admin-routes]]
[compojure.core :refer [routes wrap-routes]]
[ring.util.http-response :as response]
[compojure.route :as route]
@@ -21,6 +21,8 @@
(wrap-routes middleware/wrap-csrf)
(wrap-routes middleware/wrap-formats))
#'oauth-routes
+ (-> #'admin-routes
+ (wrap-routes middleware/wrap-restricted))
(route/not-found
(:body
(error-page {:status 404
diff --git a/src/clj/cat/middleware.clj b/src/clj/cat/middleware.clj
index 942e2f1..92e8c72 100644
--- a/src/clj/cat/middleware.clj
+++ b/src/clj/cat/middleware.clj
@@ -13,7 +13,7 @@
[immutant.web.middleware :refer [wrap-session]]
[ring.middleware.defaults :refer [site-defaults wrap-defaults]]
[buddy.auth.middleware :refer [wrap-authentication wrap-authorization]]
- [buddy.auth.accessrules :refer [restrict]]
+ [buddy.auth.accessrules :refer [restrict wrap-access-rules]]
[buddy.auth :refer [authenticated?]]
[buddy.auth.backends.session :refer [session-backend]])
(:import))
diff --git a/src/clj/cat/routes/oauth.clj b/src/clj/cat/routes/oauth.clj
index fe483be..0a0b2e2 100644
--- a/src/clj/cat/routes/oauth.clj
+++ b/src/clj/cat/routes/oauth.clj
@@ -6,9 +6,18 @@
[clojure.tools.logging :as log]
[cat.moauth :as mo]))
+(def admins #{117 ;flynn
+ })
+
(defn set-user! [user session redirect-url]
- (-> (found redirect-url)
- (assoc :session (assoc session :user user))))
+ (let [new-session (-> session
+ (assoc :user user)
+ (cond-> (contains? admins (:id user))
+ (->
+ (assoc-in [:user :admin] {:enabled false})
+ (assoc :identity "foo"))))]
+ (-> (found redirect-url)
+ (assoc :session new-session))))
(defn remove-user! [session redirect-url]
(-> (found redirect-url)
@@ -16,7 +25,7 @@
(defn clear-session! [redirect-url]
(-> (found redirect-url)
- (dissoc :session)))
+ (assoc :session nil)))
(defn oauth-init
"Initiates the Twitter OAuth"
@@ -48,4 +57,10 @@
(defroutes oauth-routes
(GET "/oauth/oauth-init" req (oauth-init req))
(GET "/oauth/oauth-callback" [& req_token :as req] (oauth-callback req_token req))
- (GET "/logout" req (remove-user! (:session req) "/")))
\ No newline at end of file
+ (GET "/logout" req (clear-session! "/")))
+
+(defroutes admin-routes
+ (GET "/admin/enable" req (-> (found "/")
+ (assoc :session (assoc-in (:session req) [:user :admin :enabled] true))))
+ (GET "/admin/disable" req (-> (found "/")
+ (assoc :session (assoc-in (:session req) [:user :admin :enabled] false)))))
\ No newline at end of file