diff options
author | slene <vslene@gmail.com> | 2014-03-22 20:49:53 +0800 |
---|---|---|
committer | slene <vslene@gmail.com> | 2014-03-22 20:49:53 +0800 |
commit | f9c07c4186b61a1548d9a908fe6228bd130f4f92 (patch) | |
tree | 7d10adada909ac74263f36a8276f2ece9988effb /modules/middleware | |
parent | 0d1872ebe3f11c14f31f454ed8d719a22c0884d0 (diff) | |
download | gitea-f9c07c4186b61a1548d9a908fe6228bd130f4f92.tar.gz gitea-f9c07c4186b61a1548d9a908fe6228bd130f4f92.zip |
update session
Diffstat (limited to 'modules/middleware')
-rw-r--r-- | modules/middleware/context.go | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go index a25a3dbbeb..c958c1d6cd 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -10,9 +10,9 @@ import ( "time" "github.com/codegangsta/martini" - "github.com/martini-contrib/sessions" "github.com/gogits/cache" + "github.com/gogits/session" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -27,7 +27,7 @@ type Context struct { p martini.Params Req *http.Request Res http.ResponseWriter - Session sessions.Session + Session session.SessionStore Cache cache.Cache User *models.User IsSigned bool @@ -92,21 +92,25 @@ func (ctx *Context) Handle(status int, title string, err error) { // InitContext initializes a classic context for a request. func InitContext() martini.Handler { - return func(res http.ResponseWriter, r *http.Request, c martini.Context, - session sessions.Session, rd *Render) { + return func(res http.ResponseWriter, r *http.Request, c martini.Context, rd *Render) { ctx := &Context{ c: c, // p: p, - Req: r, - Res: res, - Session: session, - Cache: base.Cache, - Render: rd, + Req: r, + Res: res, + Cache: base.Cache, + Render: rd, } + // start session + ctx.Session = base.SessionManager.SessionStart(res, r) + defer func() { + ctx.Session.SessionRelease(res) + }() + // Get user from session if logined. - user := auth.SignedInUser(session) + user := auth.SignedInUser(ctx.Session) ctx.User = user ctx.IsSigned = user != nil |