mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:30:54 +00:00
session: support cookie domain
This commit is contained in:
parent
474a16a7a0
commit
d7a5281bda
1
beego.go
1
beego.go
@ -362,6 +362,7 @@ func initBeforeHttpRun() {
|
|||||||
`"sessionIDHashFunc":"` + SessionHashFunc + `",` +
|
`"sessionIDHashFunc":"` + SessionHashFunc + `",` +
|
||||||
`"sessionIDHashKey":"` + SessionHashKey + `",` +
|
`"sessionIDHashKey":"` + SessionHashKey + `",` +
|
||||||
`"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` +
|
`"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` +
|
||||||
|
`"domain":` + SessionDomain + `,` +
|
||||||
`"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}`
|
`"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}`
|
||||||
}
|
}
|
||||||
GlobalSessions, err = session.NewManager(SessionProvider,
|
GlobalSessions, err = session.NewManager(SessionProvider,
|
||||||
|
@ -55,6 +55,7 @@ var (
|
|||||||
SessionHashKey string // session hash salt string.
|
SessionHashKey string // session hash salt string.
|
||||||
SessionCookieLifeTime int // the life time of session id in cookie.
|
SessionCookieLifeTime int // the life time of session id in cookie.
|
||||||
SessionAutoSetCookie bool // auto setcookie
|
SessionAutoSetCookie bool // auto setcookie
|
||||||
|
SessionDomain string // the cookie domain default is empty
|
||||||
UseFcgi bool
|
UseFcgi bool
|
||||||
MaxMemory int64
|
MaxMemory int64
|
||||||
EnableGzip bool // flag of enable gzip
|
EnableGzip bool // flag of enable gzip
|
||||||
|
@ -72,6 +72,7 @@ type managerConfig struct {
|
|||||||
SessionIDHashKey string `json:"sessionIDHashKey"`
|
SessionIDHashKey string `json:"sessionIDHashKey"`
|
||||||
CookieLifeTime int `json:"cookieLifeTime"`
|
CookieLifeTime int `json:"cookieLifeTime"`
|
||||||
ProviderConfig string `json:"providerConfig"`
|
ProviderConfig string `json:"providerConfig"`
|
||||||
|
Domain string `json:"domain"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manager contains Provider and its configuration.
|
// Manager contains Provider and its configuration.
|
||||||
@ -134,7 +135,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se
|
|||||||
Value: url.QueryEscape(sid),
|
Value: url.QueryEscape(sid),
|
||||||
Path: "/",
|
Path: "/",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: manager.config.Secure}
|
Secure: manager.config.Secure,
|
||||||
|
Domain: manager.config.Domain}
|
||||||
if manager.config.CookieLifeTime >= 0 {
|
if manager.config.CookieLifeTime >= 0 {
|
||||||
cookie.MaxAge = manager.config.CookieLifeTime
|
cookie.MaxAge = manager.config.CookieLifeTime
|
||||||
}
|
}
|
||||||
@ -153,7 +155,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se
|
|||||||
Value: url.QueryEscape(sid),
|
Value: url.QueryEscape(sid),
|
||||||
Path: "/",
|
Path: "/",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: manager.config.Secure}
|
Secure: manager.config.Secure,
|
||||||
|
Domain: manager.config.Domain}
|
||||||
if manager.config.CookieLifeTime >= 0 {
|
if manager.config.CookieLifeTime >= 0 {
|
||||||
cookie.MaxAge = manager.config.CookieLifeTime
|
cookie.MaxAge = manager.config.CookieLifeTime
|
||||||
}
|
}
|
||||||
@ -208,6 +211,7 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: manager.config.Secure,
|
Secure: manager.config.Secure,
|
||||||
|
Domain: manager.config.Domain,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oldsid, _ := url.QueryUnescape(cookie.Value)
|
oldsid, _ := url.QueryUnescape(cookie.Value)
|
||||||
|
Loading…
Reference in New Issue
Block a user