[BUGFIX] session check

This commit is contained in:
Martin/Geno 2018-08-30 10:26:23 +02:00
parent 3a887ec1c5
commit b92c33b10e
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 12 additions and 1 deletions

View File

@ -17,6 +17,9 @@ type Session struct {
}
func (ws *WebsocketServer) IsLoggedIn(msg *websocket.Message) (*Session, bool) {
if msg == nil || msg.Session == uuid.Nil {
return nil, false
}
session := Session{
SessionID: msg.Session,
}
@ -31,6 +34,10 @@ func (ws *WebsocketServer) IsLoggedIn(msg *websocket.Message) (*Session, bool) {
}
func (ws *WebsocketServer) loginHandler(logger *log.Entry, msg *websocket.Message) error {
if msg == nil || msg.Session == uuid.Nil {
logger.Warn("no session for this message detected")
return nil
}
session := Session{
SessionID: msg.Session,
}
@ -82,7 +89,7 @@ func (ws *WebsocketServer) settingsHandler(logger *log.Entry, msg *websocket.Mes
session, ok := ws.IsLoggedIn(msg)
if !ok {
msg.Answer(msg.Subject, false)
logger.Warn("logout without login")
logger.Warn("try set settings without login")
return nil
}
@ -103,6 +110,10 @@ func (ws *WebsocketServer) settingsHandler(logger *log.Entry, msg *websocket.Mes
}
func (ws *WebsocketServer) logoutHandler(logger *log.Entry, msg *websocket.Message) error {
if msg == nil || msg.Session == uuid.Nil {
logger.Warn("no session for this message detected")
return nil
}
session := Session{
SessionID: msg.Session,
}