Permalink
Browse files

Backported session shortcut from 0.2.0.

  • Loading branch information...
1 parent 650587e commit 40f67bf9398826fa0b36f96f2e360a3f0ab2fd1c @mauricemach committed Sep 9, 2011
Showing with 22 additions and 0 deletions.
  1. +1 −0 docs/zappa.html
  2. +19 −0 examples/sessions.coffee
  3. +1 −0 package.json
  4. +1 −0 src/zappa.coffee
View
@@ -182,6 +182,7 @@
<span class="nv">app: </span><span class="nx">app</span>
<span class="nv">settings: </span><span class="nx">app</span><span class="p">.</span><span class="nx">settings</span>
<span class="nv">request: </span><span class="nx">req</span>
+ <span class="nv">session: </span><span class="nx">req</span><span class="p">.</span><span class="nx">session</span>
<span class="nv">response: </span><span class="nx">res</span>
<span class="nv">next: </span><span class="nx">next</span>
<span class="nv">send: </span><span class="o">-&gt;</span> <span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">.</span><span class="nx">apply</span> <span class="nx">res</span><span class="p">,</span> <span class="nx">arguments</span>
View
@@ -0,0 +1,19 @@
+require('zappa') ->
+ use 'cookieParser', session: {secret: 'foo'}
+
+ get '/': ->
+ @user = session.user
+ render 'index'
+
+ get '/login': ->
+ session.user = 'foo'
+ redirect '/'
+
+ get '/logout': ->
+ session.user = null
+ redirect '/'
+
+ view index: ->
+ p '@user: ' + (@user or 'null')
+ p -> a href: '/login', 'login'
+ p -> a href: '/logout', 'logout'
View
@@ -31,6 +31,7 @@
"Esa-Matti Suuronen <esa-matti@suuronen.org>",
"Isaac Wolkerstorfer <agnoster@gmail.com>",
"Jason King <jasonk@amcoonline.net>",
+ "Stéphane Alnet <stephane@shimaore.net>",
"Rachel Carvalho <rachel.carvalho@gmail.com>",
"Tim Shadel <github@timshadel.com>",
"Vladimir Dronnikov <dronnikov@gmail.com>",
View
@@ -232,6 +232,7 @@ zappa.app = (func) ->
app: app
settings: app.settings
request: req
+ session: req.session
response: res
next: next
send: -> res.send.apply res, arguments

0 comments on commit 40f67bf

Please sign in to comment.