Skip to content
Browse files

sessions

  • Loading branch information...
1 parent fc6bca3 commit 3eaa9994e0d66b0b9b826a49287f1ae28494f9c1 @ducki2p committed Jan 2, 2011
Showing with 26 additions and 12 deletions.
  1. +2 −1 project.clj
  2. +5 −0 src/i2conomy/session.clj
  3. +19 −11 src/i2conomy/wallet.clj
View
3 project.clj
@@ -6,6 +6,7 @@
[ring/ring-devel "0.3.5"]
[ring/ring-jetty-adapter "0.3.5"]
[compojure "0.5.3"]
- [hiccup "0.3.1"]]
+ [hiccup "0.3.1"]
+ [sandbar/sandbar "0.3.0"]]
:dev-dependencies [[lein-run "1.0.1-SNAPSHOT"]]
:main script.run)
View
5 src/i2conomy/session.clj
@@ -0,0 +1,5 @@
+(ns i2conomy.session)
+
+(def custom-session-atom
+ "Session atom outside of the reloadables of wrap-reload"
+ (atom {}))
View
30 src/i2conomy/wallet.clj
@@ -1,14 +1,17 @@
(ns i2conomy.wallet
- (:use i2conomy.middleware)
(:require [i2conomy.mint :as mint])
- (:use compojure.core)
- (:use hiccup.core)
- (:use hiccup.page-helpers)
- (:use ring.middleware.file)
- (:use ring.middleware.file-info)
- (:use ring.middleware.reload)
- (:use ring.middleware.stacktrace)
- (:use ring.util.response))
+ (:use i2conomy.middleware
+ i2conomy.session
+ compojure.core
+ hiccup.core
+ hiccup.page-helpers
+ ring.middleware.file
+ ring.middleware.file-info
+ ring.middleware.reload
+ ring.middleware.stacktrace
+ ring.middleware.session.memory
+ ring.util.response
+ sandbar.stateful-session))
(defn view-layout [& content]
(html
@@ -19,7 +22,9 @@
:content "text/html; charset=utf-8"}]
[:title "i2conomy"]
[:link {:href "/i2conomy.css" :rel "stylesheet" :type "text/css"}]]
- [:body content])))
+ [:body
+ [:p "Account: " (session-get :account "Unknown")]
+ content])))
(defn view-balance-input []
(html
@@ -79,6 +84,7 @@
(POST "/create-account" [account]
(do
(mint/create-account account)
+ (session-put! :account account)
(view-create-account-output account)))
(POST "/pay" [from to currency amount memo]
@@ -102,5 +108,7 @@
(wrap-bounce-favicon)
(wrap-exception-logging)
(wrap-if production? wrap-failsafe)
- (wrap-if development? wrap-stacktrace)))
+ (wrap-if development? wrap-stacktrace)
+ ; prevent wrap-reload from resetting the sessions as well
+ (wrap-stateful-session {:store (memory-store custom-session-atom)})))

0 comments on commit 3eaa999

Please sign in to comment.
Something went wrong with that request. Please try again.