1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-10 02:40:17 +00:00
This commit is contained in:
astaxie
2013-11-05 22:23:48 +08:00
parent 076bd0b440
commit c8f86652a3
5 changed files with 57 additions and 1 deletions

View File

@ -25,6 +25,7 @@ type SessionStore interface {
type Provider interface {
SessionInit(maxlifetime int64, savePath string) error
SessionRead(sid string) (SessionStore, error)
SessionExist(sid string) bool
SessionRegenerate(oldsid, sid string) (SessionStore, error)
SessionDestroy(sid string) error
SessionAll() int //get all active session
@ -133,7 +134,22 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se
r.AddCookie(cookie)
} else {
sid, _ := url.QueryUnescape(cookie.Value)
session, _ = manager.provider.SessionRead(sid)
if manager.provider.SessionExist(sid) {
session, _ = manager.provider.SessionRead(sid)
} else {
sid = manager.sessionId(r)
session, _ = manager.provider.SessionRead(sid)
cookie = &http.Cookie{Name: manager.cookieName,
Value: url.QueryEscape(sid),
Path: "/",
HttpOnly: true,
Secure: manager.secure}
if manager.maxage >= 0 {
cookie.MaxAge = manager.maxage
}
http.SetCookie(w, cookie)
r.AddCookie(cookie)
}
}
return
}