Browse Source

minor refactoring

master
Christian Mueller 12 years ago
parent
commit
7267a35ab3
  1. 9
      src/NoteHub/api.clj
  2. 22
      src/NoteHub/storage.clj
  3. 4
      src/NoteHub/views/pages.clj

9
src/NoteHub/api.clj

@ -78,8 +78,7 @@ @@ -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 @@ @@ -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)

22
src/NoteHub/storage.clj

@ -32,8 +32,8 @@ @@ -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 @@ @@ -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 @@ @@ -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)))))
; 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))))

4
src/NoteHub/views/pages.clj

@ -155,7 +155,7 @@ @@ -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 @@ @@ -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))

Loading…
Cancel
Save