register, login logic works
This commit is contained in:
+16
@@ -102,6 +102,16 @@ func sendAndCloseIfFails(conn *websocket.Conn, message map[string]any) {
|
||||
}
|
||||
}
|
||||
|
||||
func sendToAllExceptAndCloseIfFails(conn *websocket.Conn, message map[string]any) {
|
||||
_, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
for _, aConn := range authenticatedConnections {
|
||||
if aConn.connection != conn {
|
||||
sendAndCloseIfFails(aConn.connection, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleUnauthenticatedMessage(ctx context.Context, conn *websocket.Conn, msg map[string]any) {
|
||||
token := msg["token"].(string)
|
||||
subject, err := GetSubject(token)
|
||||
@@ -138,5 +148,11 @@ func handleAuthenticatedMessage(conn *websocket.Conn, msg map[string]any) {
|
||||
sendAndCloseIfFails(conn, map[string]any{
|
||||
"error": "no message",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
sendToAllExceptAndCloseIfFails(conn, map[string]any{
|
||||
"username": ,
|
||||
"message": message,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user