summaryrefslogtreecommitdiff
path: root/src/mulk/benki/util.clj
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-02-29 22:45:24 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-02-29 22:45:24 +0100
commit30515c14a029c140a82729962b06eecac1745f11 (patch)
treec823bc018faa30651481aee7d092d5150870dc28 /src/mulk/benki/util.clj
parentc36256cb55640fbe452198831cb21cdeb4c570b9 (diff)
Book Marx: Implement support for page-specific authentication tokens.
Diffstat (limited to 'src/mulk/benki/util.clj')
-rw-r--r--src/mulk/benki/util.clj33
1 files changed, 21 insertions, 12 deletions
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))