File: session_filter.go

package info (click to toggle)
golang-github-revel-revel 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,240 kB
  • sloc: xml: 7; makefile: 7; javascript: 1
file content (25 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package revel

// SessionFilter is a Revel Filter that retrieves and sets the session cookie.
// Within Revel, it is available as a Session attribute on Controller instances.
// The name of the Session cookie is set as CookiePrefix + "_SESSION".
import ()

var sessionLog = RevelLog.New("section", "session")

func SessionFilter(c *Controller, fc []Filter) {
	CurrentSessionEngine.Decode(c)
	sessionWasEmpty := c.Session.Empty()

	// Make session vars available in templates as {{.session.xyz}}
	c.ViewArgs["session"] = c.Session
	c.ViewArgs["_controller"] = c

	fc[0](c, fc[1:])

	// If session is not empty or if session was not empty then
	// pass it back to the session engine to be encoded
	if !c.Session.Empty() || !sessionWasEmpty {
		CurrentSessionEngine.Encode(c)
	}
}