From 7267a35ab37b00d324eb01c5e92754897f30fc39 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Mon, 20 Jan 2014 11:52:07 +0100 Subject: [PATCH] minor refactoring --- src/NoteHub/api.clj | 9 +++------ src/NoteHub/storage.clj | 22 ++++++++++------------ src/NoteHub/views/pages.clj | 4 ++-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/NoteHub/api.clj b/src/NoteHub/api.clj index e1aaaf5..7311dfd 100644 --- a/src/NoteHub/api.clj +++ b/src/NoteHub/api.clj @@ -78,8 +78,7 @@ ;(log "post-note: %s" {:pid pid :signature signature :password password :note note}) (let [errors (filter identity [(when-not (storage/valid-publisher? pid) "pid invalid") - (when-not (= signature - (get-signature pid (storage/get-psk pid) note)) + (when-not (= signature (get-signature pid (storage/get-psk pid) note)) "signature invalid") (when (blank? note) "note is empty")])] (if (empty? errors) @@ -108,13 +107,11 @@ (defn update-note [noteID note pid signature password] ;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note}) (let [errors (filter identity - (seq [(when-not (storage/valid-publisher? pid) "pid invalid") - (when-not (= signature - (get-signature pid (storage/get-psk pid) noteID note password)) + (when-not (= signature (get-signature pid (storage/get-psk pid) noteID note password)) "signature invalid") (when (blank? note) "note is empty") - (when-not (storage/valid-password? noteID password) "password invalid")]))] + (when-not (storage/valid-password? noteID password) "password invalid")])] (if (empty? errors) (do (storage/edit-note noteID note) diff --git a/src/NoteHub/storage.clj b/src/NoteHub/storage.clj index 353ea8f..acb2c50 100644 --- a/src/NoteHub/storage.clj +++ b/src/NoteHub/storage.clj @@ -32,8 +32,8 @@ (defn create-session [] (let [token (encrypt (str (rand-int Integer/MAX_VALUE)))] - (do (redis :sadd :sessions token) - token))) + (redis :sadd :sessions token) + token)) (defn invalidate-session [token] (let [was-valid (redis :sismember :sessions token)] @@ -91,14 +91,13 @@ (defn resolve-url [url] (let [value (redis :hget :short-url url)] - (when value + (when value ; TODO: necessary? (read-string value)))) (defn delete-short-url [noteID] (let [value (redis :hget :short-url noteID)] - (do - (redis :hdel :short-url noteID) - (redis :hdel :short-url value)))) + (redis :hdel :short-url noteID) + (redis :hdel :short-url value))) (defn create-short-url "Creates a short url for the given request metadata or extracts @@ -116,9 +115,8 @@ url (first (remove short-url-exists? (map hash-to-string hash-stream)))] - (do - ; we create two mappings: key params -> short url and back, - ; s.t. we can later easily check whether a short url already exists - (redis :hset :short-url url key) - (redis :hset :short-url key url) - url))))) \ No newline at end of file + ; we create two mappings: key params -> short url and back, + ; s.t. we can later easily check whether a short url already exists + (redis :hset :short-url url key) + (redis :hset :short-url key url) + url)))) \ No newline at end of file diff --git a/src/NoteHub/views/pages.clj b/src/NoteHub/views/pages.clj index 0174d40..16d7580 100644 --- a/src/NoteHub/views/pages.clj +++ b/src/NoteHub/views/pages.clj @@ -155,7 +155,7 @@ (let [pid "NoteHub" psk (storage/get-psk pid)] (if (storage/valid-publisher? pid) - (let [resp (api/post-note note pid (api/get-signature (str pid psk note)) password)] + (let [resp (api/post-note note pid (api/get-signature pid psk note) password)] (if (and (storage/invalidate-session session) (get-in resp [:status :success])) @@ -170,7 +170,7 @@ psk (storage/get-psk pid)] (if (storage/valid-publisher? pid) (let [resp (api/update-note noteID note pid - (api/get-signature (str pid psk noteID note password)) + (api/get-signature pid psk noteID note password) password)] (if (get-in resp [:status :success]) (redirect (:longURL resp))