Add API Framework Revel Source Files
[iec.git] / src / foundation / api / revel / session_filter.go
1 package revel
2
3 // SessionFilter is a Revel Filter that retrieves and sets the session cookie.
4 // Within Revel, it is available as a Session attribute on Controller instances.
5 // The name of the Session cookie is set as CookiePrefix + "_SESSION".
6 import ()
7
8 var sessionLog = RevelLog.New("section", "session")
9
10 func SessionFilter(c *Controller, fc []Filter) {
11         CurrentSessionEngine.Decode(c)
12         sessionWasEmpty := c.Session.Empty()
13
14         // Make session vars available in templates as {{.session.xyz}}
15         c.ViewArgs["session"] = c.Session
16         c.ViewArgs["_controller"] = c
17
18         fc[0](c, fc[1:])
19
20         // If session is not empty or if session was not empty then
21         // pass it back to the session engine to be encoded
22         if !c.Session.Empty() || !sessionWasEmpty {
23                 CurrentSessionEngine.Encode(c)
24         }
25 }