Skip to content

Instantly share code, notes, and snippets.

@ibdknox
Created July 25, 2011 00:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ibdknox/1103278 to your computer and use it in GitHub Desktop.
Save ibdknox/1103278 to your computer and use it in GitHub Desktop.
sessions and cookies
(require '[noir.cookies :as cookies])
(cookies/put! :user-id 2)
(cookies/get :user-id)
;; => 2
(cookies/get :username "anon")
;; => "anon"
;; you can also pass a map that has all the cookie's attributes
(cookies/put! :tracker {:value 29649 :path "/" :expires 1})
(session/flash-put! "User added!")
(session/flash-get)
;; => "User added!"
;;
(session/flash-get)
;; => nil
(require '[noir.session :as session])
(session/put! :username "chris")
(session/get :username)
;; => "chris"
(session/remove! :username)
(session/get :username)
;; => nil
(session/get :username "anon")
;; => "anon"
(session/put! :username "chris")
(session/put! :user-id 2)
(session/clear!)
(use 'noir.util.test)
(deftest cookies-get
(with-noir
(is (nil? (cookies/get :noir)))
(is (= "noir" (cookies/get :noir "noir")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment