Fix the notification

This commit is contained in:
Las Zenow 2013-09-03 00:03:34 +02:00
parent ea3d88bb70
commit 7410ae7942
2 changed files with 22 additions and 23 deletions

View file

@ -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

View file

@ -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
}