diff --git a/session.go b/session.go index 6430115..4db5a5d 100644 --- a/session.go +++ b/session.go @@ -16,13 +16,29 @@ type Notification struct { } type Session struct { - User string - Role string - Notif []Notification - S *sessions.Session + User string + Role string + S *sessions.Session } -func getNotif(session *sessions.Session) []Notification { +func GetSession(r *http.Request) (s *Session) { + s = new(Session) + var err error + s.S, err = sesStore.Get(r, "session") + if err == nil && !s.S.IsNew { + s.User, _ = s.S.Values["user"].(string) + s.Role = db.UserRole(s.User) + } + + if s.S.IsNew { + s.S.Values["id"] = hex.EncodeToString(securecookie.GenerateRandomKey(16)) + } + + return +} + +func (s *Session) GetNotif() []Notification { + session := s.S msgs := session.Flashes("nMsg") titles := session.Flashes("nTitle") tpes := session.Flashes("nType") @@ -36,23 +52,6 @@ func getNotif(session *sessions.Session) []Notification { return notif } -func GetSession(r *http.Request) (s *Session) { - s = new(Session) - var err error - s.S, err = sesStore.Get(r, "session") - if err == nil && !s.S.IsNew { - s.User, _ = s.S.Values["user"].(string) - s.Role = db.UserRole(s.User) - s.Notif = getNotif(s.S) - } - - if s.S.IsNew { - s.S.Values["id"] = hex.EncodeToString(securecookie.GenerateRandomKey(16)) - } - - return -} - func (s *Session) LogIn(user string) { s.User = user s.S.Values["user"] = user diff --git a/template.go b/template.go index dc41ba3..30a820b 100644 --- a/template.go +++ b/template.go @@ -30,7 +30,7 @@ func GetStatus(w http.ResponseWriter, r *http.Request) Status { s.FullURL = s.BaseURL + r.RequestURI s.User = sess.User s.IsAdmin = sess.IsAdmin() - s.Notif = sess.Notif + s.Notif = sess.GetNotif() return s }