diff --git a/web/administrator.go b/web/administrator.go index 5456f75..4b334f1 100644 --- a/web/administrator.go +++ b/web/administrator.go @@ -235,6 +235,8 @@ func (this *Administrator) UpdateAccount(ctx *Context) { if ctx.Session.Email == originAccount.Email { ctx.Session.Email = "" delete(ctx.Session.Data, "role") + ctx.Session.Store() + outJSONWithCode(ctx.W, http.StatusUnauthorized, nil) return } diff --git a/web/authentication.go b/web/authentication.go index 78c7f6b..c8c51af 100644 --- a/web/authentication.go +++ b/web/authentication.go @@ -123,6 +123,8 @@ func (this *Authentication) GetAuthSession(ctx *Context) { ctx.Session.Email = u.Email ctx.Session.Data["role"] = u.Role + ctx.Session.Store() + authInfo.Role = u.Role authInfo.Email = u.Email @@ -133,6 +135,8 @@ func (this *Authentication) GetAuthSession(ctx *Context) { func (this *Authentication) DeleteAuthSession(ctx *Context) { ctx.Session.Email = "" delete(ctx.Session.Data, "role") + ctx.Session.Store() + outJSONWithCode(ctx.W, http.StatusOK, nil) } diff --git a/web/base.go b/web/base.go index 5a051e4..65528f7 100644 --- a/web/base.go +++ b/web/base.go @@ -83,9 +83,6 @@ func authHandler(needAuth bool) func(*Context) bool { ctx.Session, err = sessManager.Get(ctx.W, ctx.R) if ctx.Session != nil { ctx.Todo(func() { - if ctx.Session.Email == "" { - return - } if err := sessManager.Store(ctx.Session); err != nil { log.Errorf("Failed to store session: %s.", err.Error()) } @@ -124,7 +121,7 @@ func (b BaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { buf.Write(debug.Stack()) stack = buf.String() - // outJSONWithCode(ctx.W, http.StatusInternalServerError, "Internal Server Error") + outJSONWithCode(w, http.StatusInternalServerError, "Internal Server Error") log.Errorf("%v\n\n%s\n", err_, stack) return diff --git a/web/session/session.go b/web/session/session.go index 489a009..660eb76 100644 --- a/web/session/session.go +++ b/web/session/session.go @@ -34,6 +34,7 @@ type storeData struct { } type Session struct { + m SessionManager key string storeData } @@ -41,6 +42,13 @@ type Session struct { func (s *Session) ID() string { return s.key } +func (s *Session) Store() error { + err := s.m.Store(s) + if err != nil { + log.Errorf("Failed to store session[%s]: %s", s.key, err.Error()) + } + return err +} type EtcdStore struct { client *cronsun.Client @@ -63,6 +71,7 @@ func (this *EtcdStore) Get(w http.ResponseWriter, r *http.Request) (sess *Sessio } sess = &Session{ + m: this, storeData: storeData{ Data: make(map[interface{}]interface{}, 2), },