summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-11-29 11:52:54 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-11-29 11:52:54 +0100
commitb786befe6d4989cf109da741ff1d3968da2dadfd (patch)
treef69db3f3e7573f098a9c272bb22484b218576b17 /src
parent4a262e09f56f07a009a2d6ad0d360b818ff68ebf (diff)
Allow the user to log in as needed.
Diffstat (limited to 'src')
-rw-r--r--src/logikorr/servlet.clj37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/logikorr/servlet.clj b/src/logikorr/servlet.clj
index 6eef643..dc48ce5 100644
--- a/src/logikorr/servlet.clj
+++ b/src/logikorr/servlet.clj
@@ -141,26 +141,27 @@
(ds/create (assoc (dissoc student :key) :kind "student") (:key new)))
(str (:number new)))))
+(defn call-with-authentication [thunk]
+ (let [users (UserServiceFactory/getUserService)
+ user (.getCurrentUser users)]
+ (if (and user
+ (some #(= user %) #{"mulkiatsch@gmail.com"
+ "gpmfuchs@gmx.de"
+ "kilian@fachschaften.uni-muenchen.de"
+ "schwicht@mathematik.uni-muenchen.de"}))
+ (thunk)
+ (redirect-to (.createLoginURL users "/")))))
+
+(defmacro with-authentication [& body]
+ `(call-with-authentication (fn [] ~@body)))
+
(defroutes logikorr
- (GET "/*" (let [users (UserServiceFactory/getUserService)
- user (.getCurrentUser users)]
- (if (and user
- (some #(= user %) #{"mulkiatsch@gmail.com"
- "gpmfuchs@gmx.de"
- "kilian@fachschaften.uni-muenchen.de"
- "schwicht@mathematik.uni-muenchen.de"}))
- :next
- (html [:html
- [:head [:title "Access denied."]]
- [:body
- [:h1 "Access denied."]
- [:p "You do not have access to this application."]]]))))
- (GET "/" index)
+ (GET "/" (with-authentication (index request)))
(GET "/favicon.ico" (do nil))
- (GET "/logikorr-completion-data.js" (compute-completion-data-js))
- (GET "/find-student" (find-student-json (:name params)))
- (GET "/update-student-score" (update-student-score (:id params) (:score-number params) (:score params)))
- (GET "/make-new-revision" (make-new-revision))
+ (GET "/logikorr-completion-data.js" (with-authentication (compute-completion-data-js)))
+ (GET "/find-student" (with-authentication (find-student-json (:name params))))
+ (GET "/update-student-score" (with-authentication (update-student-score (:id params) (:score-number params) (:score params))))
+ (GET "/make-new-revision" (with-authentication (make-new-revision)))
(GET "/*"
(or (serve-file *static-directory* (params :*)) :next))
(ANY "/*" (page-not-found)))