mirror of https://github.com/shunfei/cronsun
store session data manually
parent
e3fcfb59b7
commit
e4c5cac014
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue