6af2778a by astaxie

fix set cookies many times

1 parent 18bf4749
...@@ -66,6 +66,6 @@ func (ctx *Context) SetCookie(name string, value string, age int64) { ...@@ -66,6 +66,6 @@ func (ctx *Context) SetCookie(name string, value string, age int64) {
66 } else { 66 } else {
67 utctime = time.Unix(time.Now().Unix()+age, 0) 67 utctime = time.Unix(time.Now().Unix()+age, 0)
68 } 68 }
69 cookie := fmt.Sprintf("%s=%s; expires=%s", name, value, webTime(utctime)) 69 cookie := fmt.Sprintf("%s=%s; Expires=%s; Path=/", name, value, webTime(utctime))
70 ctx.SetHeader("Set-Cookie", cookie, false) 70 ctx.SetHeader("Set-Cookie", cookie, true)
71 } 71 }
......
...@@ -21,12 +21,13 @@ import ( ...@@ -21,12 +21,13 @@ import (
21 ) 21 )
22 22
23 type Controller struct { 23 type Controller struct {
24 Ctx *Context 24 Ctx *Context
25 Data map[interface{}]interface{} 25 Data map[interface{}]interface{}
26 ChildName string 26 ChildName string
27 TplNames string 27 TplNames string
28 Layout string 28 Layout string
29 TplExt string 29 TplExt string
30 CruSession session.SessionStore
30 } 31 }
31 32
32 type ControllerInterface interface { 33 type ControllerInterface interface {
...@@ -58,6 +59,9 @@ func (c *Controller) Prepare() { ...@@ -58,6 +59,9 @@ func (c *Controller) Prepare() {
58 } 59 }
59 60
60 func (c *Controller) Finish() { 61 func (c *Controller) Finish() {
62 if c.CruSession != nil {
63 c.CruSession.SessionRelease()
64 }
61 } 65 }
62 66
63 func (c *Controller) Get() { 67 func (c *Controller) Get() {
...@@ -259,25 +263,30 @@ func (c *Controller) SaveToFile(fromfile, tofile string) error { ...@@ -259,25 +263,30 @@ func (c *Controller) SaveToFile(fromfile, tofile string) error {
259 return nil 263 return nil
260 } 264 }
261 265
262 func (c *Controller) StartSession() (sess session.SessionStore) { 266 func (c *Controller) StartSession() session.SessionStore {
263 sess = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request) 267 if c.CruSession == nil {
264 return 268 c.CruSession = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)
269 }
270 return c.CruSession
265 } 271 }
266 272
267 func (c *Controller) SetSession(name string, value interface{}) { 273 func (c *Controller) SetSession(name string, value interface{}) {
268 ss := c.StartSession() 274 if c.CruSession == nil {
269 defer ss.SessionRelease() 275 c.StartSession()
270 ss.Set(name, value) 276 }
277 c.CruSession.Set(name, value)
271 } 278 }
272 279
273 func (c *Controller) GetSession(name string) interface{} { 280 func (c *Controller) GetSession(name string) interface{} {
274 ss := c.StartSession() 281 if c.CruSession == nil {
275 defer ss.SessionRelease() 282 c.StartSession()
276 return ss.Get(name) 283 }
284 return c.CruSession.Get(name)
277 } 285 }
278 286
279 func (c *Controller) DelSession(name string) { 287 func (c *Controller) DelSession(name string) {
280 ss := c.StartSession() 288 if c.CruSession == nil {
281 defer ss.SessionRelease() 289 c.StartSession()
282 ss.Delete(name) 290 }
291 c.CruSession.Delete(name)
283 } 292 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!