session key problem at preview fixed
This commit is contained in:
+5
-3
@@ -10,6 +10,7 @@
|
|||||||
; frequently used selectors
|
; frequently used selectors
|
||||||
(def $draft ($ :#draft))
|
(def $draft ($ :#draft))
|
||||||
(def $preview ($ :#preview))
|
(def $preview ($ :#preview))
|
||||||
|
(def $session-key ($ :#session-key))
|
||||||
(def $preview-start-line ($ :#preview-start-line))
|
(def $preview-start-line ($ :#preview-start-line))
|
||||||
|
|
||||||
(defn scroll-to
|
(defn scroll-to
|
||||||
@@ -30,12 +31,13 @@
|
|||||||
(.click ($ :#preview-button)
|
(.click ($ :#preview-button)
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(do
|
(do
|
||||||
(fm/remote (md-to-html (val $draft)) [result]
|
(fm/remote (get-preview-md (val $session-key) (val $draft)) [{:keys [preview session-key]}]
|
||||||
(show $preview-start-line)
|
(show $preview-start-line)
|
||||||
(inner $preview result)
|
(inner $preview preview)
|
||||||
|
(val $session-key session-key)
|
||||||
(scroll-to $preview-start-line)))))
|
(scroll-to $preview-start-line)))))
|
||||||
|
|
||||||
(.click ($ :#publish-button)
|
(.click ($ :#publish-button)
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(val ($ :#session-value)
|
(val ($ :#session-value)
|
||||||
(nh/hash #(.charCodeAt % 0) (str (val $draft) (val ($ :#session-key)))))))
|
(nh/hash #(.charCodeAt % 0) (str (val $draft) (val $session-key))))))
|
||||||
|
|||||||
@@ -89,14 +89,16 @@
|
|||||||
:border-bottom [:1px :dashed :gray]
|
:border-bottom [:1px :dashed :gray]
|
||||||
:margin-bottom :5em)
|
:margin-bottom :5em)
|
||||||
(rule "h1, h2, h3, h4"
|
(rule "h1, h2, h3, h4"
|
||||||
:font-family (gen-comma-list "'Noticia Text'" "Georgia"))))
|
:font-family (gen-comma-list "'Noticia Text'" "'PT Serif'"))))
|
||||||
|
|
||||||
(defpartial layout [title & content]
|
(defpartial layout [title & content]
|
||||||
(html5
|
(html5
|
||||||
[:head
|
[:head
|
||||||
[:title "NoteHub — " title]
|
[:title "NoteHub — " title]
|
||||||
(include-js "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js")
|
(include-js "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js")
|
||||||
[:link {:href "http://fonts.googleapis.com/css?family=Noticia+Text:400,700"
|
[:link {:href (str "http://fonts.googleapis.com/css?family="
|
||||||
|
"PT+Serif:700|Noticia+Text:700"
|
||||||
|
"&subset=latin,cyrillic" )
|
||||||
:rel "stylesheet"
|
:rel "stylesheet"
|
||||||
:type "text/css"}]
|
:type "text/css"}]
|
||||||
[:style {:type "text/css"} global-css]]
|
[:style {:type "text/css"} global-css]]
|
||||||
|
|||||||
@@ -20,8 +20,19 @@
|
|||||||
(def max-title-length 80)
|
(def max-title-length 80)
|
||||||
|
|
||||||
; Markdown -> HTML mapper
|
; Markdown -> HTML mapper
|
||||||
(defremote md-to-html [draft]
|
(defn md-to-html [md-text]
|
||||||
(.markdownToHtml (PegDownProcessor.) draft))
|
(.markdownToHtml (PegDownProcessor.) md-text))
|
||||||
|
|
||||||
|
(defn get-flash-key []
|
||||||
|
(let [k (encrypt (str (rand-int Integer/MAX_VALUE)))]
|
||||||
|
(do (flash-put! k true)
|
||||||
|
(print-str k))))
|
||||||
|
|
||||||
|
; This function answers to a corresponding AJAX request
|
||||||
|
(defremote get-preview-md [session-key md]
|
||||||
|
(when (flash-get session-key)
|
||||||
|
{:session-key (get-flash-key)
|
||||||
|
:preview (md-to-html md)}))
|
||||||
|
|
||||||
; Template for the error sites
|
; Template for the error sites
|
||||||
(defn page-setter [code message]
|
(defn page-setter [code message]
|
||||||
@@ -50,8 +61,7 @@
|
|||||||
(common/layout "New Markdown Note"
|
(common/layout "New Markdown Note"
|
||||||
[:div.central-element
|
[:div.central-element
|
||||||
(form-to [:post "/post-note"]
|
(form-to [:post "/post-note"]
|
||||||
(hidden-field :session-key (let [k (encrypt (str (rand-int Integer/MAX_VALUE)))]
|
(hidden-field :session-key (get-flash-key))
|
||||||
(do (flash-put! k true) (print-str k))))
|
|
||||||
(hidden-field {:id :session-value} :session-value)
|
(hidden-field {:id :session-value} :session-value)
|
||||||
(text-area {:class :max-width} :draft)
|
(text-area {:class :max-width} :draft)
|
||||||
[:div#buttons.hidden
|
[:div#buttons.hidden
|
||||||
@@ -90,6 +100,7 @@
|
|||||||
valid-hash (= (Short/parseShort session-value) ; the hash code is correct
|
valid-hash (= (Short/parseShort session-value) ; the hash code is correct
|
||||||
(nh/hash #(.codePointAt % 0) (str draft session-key)))]
|
(nh/hash #(.codePointAt % 0) (str draft session-key)))]
|
||||||
(do
|
(do
|
||||||
|
; TODO: delete this if tests are written
|
||||||
(println "session:" valid-session "draft:" valid-draft "hash:"
|
(println "session:" valid-session "draft:" valid-draft "hash:"
|
||||||
(Short/parseShort session-value)
|
(Short/parseShort session-value)
|
||||||
(nh/hash #(.codePointAt % 0) (str draft session-key)))
|
(nh/hash #(.codePointAt % 0) (str draft session-key)))
|
||||||
|
|||||||
Reference in New Issue
Block a user