public IWebMessage Post([FromBody] NewMessage msg)
 {
     msg.UserId = _auth.Authenticate(HttpContext).Id;
     if (ModelState.IsValid)
     {
         //Message object is good:
         IWebMessage message = _manager.Create(msg);
         if (message != null)
         {
             return(message);
         }
     }
     throw new Exception("Invalid Message Data - ARGH");
 }
        public override async void OnConnected(WebSocket socket, HttpContext context)
        {
            var user = _am.Authenticate(context);

            if (user == null)
            {
                socket.Abort(); return;
            }
            base.OnConnected(socket, context);
            var socketUser = new SocketUser(user, _cm, socket);

            AllConnectedUsers.TryAdd(socket, socketUser);
            foreach (var c in socketUser.SubscribedChannels)
            {
                Channels.TryGetValue(c.Id, out SocketChannel channel);
                channel.JoinChannel(socketUser);
            }

            var socketId = WSManager.GetId(socket);

            await SendMessageToAllAsync("{ \"type\": \"USERCONNECTED\", \"message\":\"" + user.Email + " is now connected\"}");
        }
Example #3
0
        public IActionResult UserDetails()
        {
            var x = _manager.Authenticate(HttpContext);

            return(View(x));
        }
        public IEnumerable <IChannel> Get()
        {
            var userId = _am.Authenticate(HttpContext).Id;

            return(_cm.GetSubscribedChannels(userId));
        }