Browse Source

session key problem at preview fixed

master
Christian Mueller 14 years ago
parent
commit
a1527fec21
  1. 8
      src-cljs/main.cljs
  2. 6
      src/NoteHub/views/common.clj
  3. 19
      src/NoteHub/views/pages.clj

8
src-cljs/main.cljs

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
; frequently used selectors
(def $draft ($ :#draft))
(def $preview ($ :#preview))
(def $session-key ($ :#session-key))
(def $preview-start-line ($ :#preview-start-line))
(defn scroll-to
@ -30,12 +31,13 @@ @@ -30,12 +31,13 @@
(.click ($ :#preview-button)
(fn [e]
(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)
(inner $preview result)
(inner $preview preview)
(val $session-key session-key)
(scroll-to $preview-start-line)))))
(.click ($ :#publish-button)
(fn [e]
(val ($ :#session-value)
(nh/hash #(.charCodeAt % 0) (str (val $draft) (val ($ :#session-key)))))))
(nh/hash #(.charCodeAt % 0) (str (val $draft) (val $session-key))))))

6
src/NoteHub/views/common.clj

@ -89,14 +89,16 @@ @@ -89,14 +89,16 @@
:border-bottom [:1px :dashed :gray]
:margin-bottom :5em)
(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]
(html5
[:head
[:title "NoteHub — " title]
(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"
:type "text/css"}]
[:style {:type "text/css"} global-css]]

19
src/NoteHub/views/pages.clj

@ -20,8 +20,19 @@ @@ -20,8 +20,19 @@
(def max-title-length 80)
; Markdown -> HTML mapper
(defremote md-to-html [draft]
(.markdownToHtml (PegDownProcessor.) draft))
(defn md-to-html [md-text]
(.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
(defn page-setter [code message]
@ -50,8 +61,7 @@ @@ -50,8 +61,7 @@
(common/layout "New Markdown Note"
[:div.central-element
(form-to [:post "/post-note"]
(hidden-field :session-key (let [k (encrypt (str (rand-int Integer/MAX_VALUE)))]
(do (flash-put! k true) (print-str k))))
(hidden-field :session-key (get-flash-key))
(hidden-field {:id :session-value} :session-value)
(text-area {:class :max-width} :draft)
[:div#buttons.hidden
@ -90,6 +100,7 @@ @@ -90,6 +100,7 @@
valid-hash (= (Short/parseShort session-value) ; the hash code is correct
(nh/hash #(.codePointAt % 0) (str draft session-key)))]
(do
; TODO: delete this if tests are written
(println "session:" valid-session "draft:" valid-draft "hash:"
(Short/parseShort session-value)
(nh/hash #(.codePointAt % 0) (str draft session-key)))

Loading…
Cancel
Save