示例#1
0
        private void HandleLogout(HttpListenerContext context)
        {
            var token = RestMethods.GetToken(context.Request);

            if (!_tokens.TryRemove(token, out var id))
            {
                RestMethods.WriteError(context.Response, HttpStatusCode.Unauthorized, "Authorization failed");
                return;
            }
            _users.TryRemove(id, out var user);
            _usernames.TryRemove(user.Username, out id);

            SendToAllSubscribers(WebSocketJsonType.DeletedResource, new DeletedItem
            {
                Item = user,
                Type = WebSocketJsonType.User
            });

            context.Response.StatusCode = (int)HttpStatusCode.NoContent;
            context.Response.OutputStream.Close();
        }
示例#2
0
        private bool VerifyToken(HttpListenerRequest request)
        {
            var token = RestMethods.GetToken(request);

            return(_tokens.ContainsKey(token));
        }