From b92c33b10e76673412ee59ed05bd9eecbe2fb4e5 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Thu, 30 Aug 2018 10:26:23 +0200 Subject: [PATCH] [BUGFIX] session check --- websocket/hd_auth.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/websocket/hd_auth.go b/websocket/hd_auth.go index c69563c..82663eb 100644 --- a/websocket/hd_auth.go +++ b/websocket/hd_auth.go @@ -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, }