From 30515c14a029c140a82729962b06eecac1745f11 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Wed, 29 Feb 2012 22:45:24 +0100 Subject: Book Marx: Implement support for page-specific authentication tokens. --- src/mulk/benki/util.clj | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/mulk/benki/util.clj') diff --git a/src/mulk/benki/util.clj b/src/mulk/benki/util.clj index 3600f9e..0c91b7d 100644 --- a/src/mulk/benki/util.clj +++ b/src/mulk/benki/util.clj @@ -7,12 +7,17 @@ [noir.request :as request] [noir.response :as response] [clojure.java.jdbc :as sql]) - (:import [java.text DateFormat])) + (:import [java.text DateFormat] + [java.security SecureRandom] + [java.math BigInteger])) (def fmt clojure.pprint/cl-format) +(def ^:dynamic *user*) + + (defonce #^:private finished-initializations (atom #{})) (defmacro do-once [key & body] @@ -42,21 +47,20 @@ content (:bottom kind)])) - -(defn fresolve [s & args] - (resolve-uri (apply fmt nil s args))) - -(defn link [& args] +(defn linkrel [& args] (match [(vec args)] - [[:login]] (fresolve "/login") - [[:marx]] (fresolve "/marx") - [[:marx :submit]] (fresolve "/marx/submit") - [[:marx id]] (fresolve "/marx/~a" id) - [[:wiki title & xs]] (fresolve "/wiki/~a~@[~a~]" title (first xs)) + [[:login]] (fmt nil "/login") + [[:marx]] (fmt nil "/marx") + [[:marx :submit]] (fmt nil "/marx/submit") + [[:marx id]] (fmt nil "/marx/~a" id) + [[:wiki title & xs]] (fmt nil "/wiki/~a~@[~a~]" title (first xs)) )) +(defn link [& args] + (resolve-uri (apply linkrel args))) + (defn call-with-auth [thunk] - (if (session/get :user) + (if *user* (thunk) (do (session/flash-put! (:uri (request/ring-request))) (response/redirect "/login")))) @@ -70,3 +74,8 @@ (defn format-date [x] (.format (DateFormat/getDateTimeInstance DateFormat/FULL DateFormat/FULL) x)) + +(defonce secure-random (SecureRandom.)) +(defn genkey [] + ;;(.toString (BigInteger. 260 secure-random) 32) + (BigInteger. 260 secure-random)) -- cgit v1.2.3