示例#1
0
        private bool SaveOrUpdateChannel(IHttpSession session, IHttpResponse response, IHttpInput input, int channelId, bool delete)
        {
            if (!input.ContainsAndNotNull("SessionId", "ParentChannelId", "Name", "Description", "UserLimit") || session.Id != input["SessionId"].Value)
            {
                WriteAndFlush(response, "{ \"error\": \"Invalid request\" }");
                return(true);
            }

            ChannelEditMessage editMessage;
            ChannelInfo        channel = new ChannelInfo(channelId);

            if (!delete)
            {
                int userLimit, parentChannelId;
                if (!Int32.TryParse(input["ParentChannelId"].Value, out parentChannelId))
                {
                    WriteAndFlush(response, "{ \"error\": \"Invalid request\" }");
                    return(true);
                }

                if (!Int32.TryParse(input["UserLimit"].Value, out userLimit))
                {
                    WriteAndFlush(response, "{ \"error\": \"Invalid request\" }");
                    return(true);
                }

                channel.ParentChannelId = parentChannelId;
                channel.Name            = input["Name"].Value.Trim();
                channel.Description     = input["Description"].Value.Trim();
                channel.UserLimit       = userLimit;

                bool defaultChannel;
                if (!Boolean.TryParse(input["Default"].Value, out defaultChannel))
                {
                    WriteAndFlush(response, "{ \"error\": \"Invalid request\" }");
                    return(true);
                }

                editMessage = new ChannelEditMessage(channel)
                {
                    MakeDefault = defaultChannel
                };
            }
            else
            {
                editMessage = new ChannelEditMessage(channel)
                {
                    Delete = true
                };
            }

            var msg = Connections.SendAndReceive <ChannelEditResultMessage> (editMessage, session);

            WriteAndFlush(response, JsonConvert.SerializeObject(new { msg.ChannelId, msg.Result }));
            return(false);
        }
示例#2
0
        protected override bool ProcessSection(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            if (request.UriParts.Length == 1)
            {
                PermissionDeniedMessage pmsg;
                var listmsg = Connections.SendAndReceive <UserListMessage> (new RequestUserListMessage(UserListMode.All), session, out pmsg);

                if (pmsg != null)
                {
                    WriteAndFlush(response, "{ \"error\": \"Permission denied\" }");
                    return(true);
                }

                WriteAndFlush(response, JsonConvert.SerializeObject(listmsg.Users.RunQuery(request.QueryString)));
                return(true);
            }
            else if (request.UriParts.Length == 2)
            {
                int userId;
                if (!request.TryGetItemId(out userId))
                {
                    WriteAndFlush(response, "{ \"error\": \"Invalid request\" }");
                    return(true);
                }

                switch (request.UriParts[1].Trim().ToLower())
                {
                //case "delete":
                case "edit":
                {
                    IHttpInput input = (request.Method.ToLower() == "post") ? request.Form : request.QueryString;

                    if (!input.ContainsAndNotNull("SessionId", "Permissions") || session.Id != input["SessionId"].Value)
                    {
                        WriteAndFlush(response, "{ \"error\": \"Invalid request\" }");
                        return(true);
                    }

                    var permissions = JsonConvert.DeserializeObject <IEnumerable <Permission> > (input["Permissions"].Value).ToList();
                    if (permissions.Count == 0)
                    {
                        return(true);
                    }

                    Connections.Send(new SetPermissionsMessage(userId, permissions), session);
                    return(true);
                }
                }
            }

            WriteAndFlush(response, "{ \"error\": \"Invalid request\" }");
            return(true);
        }
示例#3
0
        private bool SaveOrUpdateChannel(IHttpSession session, IHttpResponse response, IHttpInput input, int channelId, bool delete)
        {
            if (!input.ContainsAndNotNull ("SessionId", "ParentChannelId", "Name", "Description", "UserLimit") || session.Id != input["SessionId"].Value)
            {
                WriteAndFlush (response, "{ \"error\": \"Invalid request\" }");
                return true;
            }

            ChannelEditMessage editMessage;
            ChannelInfo channel = new ChannelInfo (channelId);

            if (!delete)
            {
                int userLimit, parentChannelId;
                if (!Int32.TryParse(input["ParentChannelId"].Value, out parentChannelId))
                {
                    WriteAndFlush (response, "{ \"error\": \"Invalid request\" }");
                    return true;
                }

                if (!Int32.TryParse(input["UserLimit"].Value, out userLimit))
                {
                    WriteAndFlush (response, "{ \"error\": \"Invalid request\" }");
                    return true;
                }

                channel.ParentChannelId = parentChannelId;
                channel.Name = input["Name"].Value.Trim();
                channel.Description = input["Description"].Value.Trim();
                channel.UserLimit = userLimit;

                bool defaultChannel;
                if (!Boolean.TryParse (input["Default"].Value, out defaultChannel))
                {
                    WriteAndFlush (response, "{ \"error\": \"Invalid request\" }");
                    return true;
                }

                editMessage = new ChannelEditMessage (channel) { MakeDefault = defaultChannel };
            }
            else
            {
                editMessage = new ChannelEditMessage (channel) { Delete = true };
            }

            var msg = Connections.SendAndReceive<ChannelEditResultMessage> (editMessage, session);
            WriteAndFlush (response, JsonConvert.SerializeObject (new { msg.ChannelId, msg.Result }));
            return false;
        }