예제 #1
0
파일: session.go 프로젝트: intZz/leanote
// 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".
func SessionFilter(c *revel.Controller, fc []revel.Filter) {
	session := restoreSession(c.Request.Request)
	// c.Session, 重新生成一个revel.Session给controller!!!
	//	Log("sessoin--------")
	//	LogJ(session)
	revelSession := revel.Session(session) // 强制转换 还是同一个对象, 但有个问题, 这样Session.Id()方法是用revel的了
	c.Session = revelSession
	// 生成sessionId
	c.Session.Id()
	sessionWasEmpty := len(c.Session) == 0

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

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

	// Store the signed session if it could have changed.
	if len(c.Session) > 0 || !sessionWasEmpty {
		// 转换成lea.Session
		session = Session(c.Session)
		c.SetCookie(session.cookie())
	}
}