/// <summary> /// /// </summary> /// <param name="errors">collection that all validation errors are added to.</param> /// <param name="form">form that validation should be made on.</param> public FormValidator(IHttpInput form, NameValueCollection errors) : base(errors) { if (form == null) throw new ArgumentNullException("form"); _form = form; }
/// <summary> /// Recursive function that will go through an xml element and store it's content /// to the form item. /// </summary> /// <param name="item">(parent) Item in form that content should be added to.</param> /// <param name="node">Node that should be parsed.</param> public void TraverseNode(IHttpInput item, XmlNode node) { // Add text node content to previous item if (node.Name == "#text") { HttpInputItem formItem = item as HttpInputItem; if (formItem != null) { formItem.Add(node.InnerText.Trim()); return; } } string name = node.Name.ToLower(); item.Add(name, node.Value); IHttpInput myItem = item[name]; if (node.Attributes != null) { foreach (XmlAttribute attribute in node.Attributes) { myItem.Add(attribute.Name.ToLower(), attribute.Value); } } foreach (XmlNode childNode in node.ChildNodes) { TraverseNode(myItem, childNode); } }
/// <summary> /// Switch to a new http input. /// </summary> /// <param name="form">form to use validation for now</param> public void SetForm(IHttpInput form) { if (form == null) { throw new ArgumentNullException("form"); } _form = form; }
/// <summary> /// /// </summary> /// <param name="errors">collection that all validation errors are added to.</param> /// <param name="form">form that validation should be made on.</param> public FormValidator(IHttpInput form, NameValueCollection errors) : base(errors) { if (form == null) { throw new ArgumentNullException("form"); } _form = form; }
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); }
/// <summary> /// Switch to a new http input. /// </summary> /// <param name="form">form to use validation for now</param> /// <param name="modelLanguage">language for the validation</param> public void SetForm(IHttpInput form, ILanguageNode modelLanguage) { if (form == null) { throw new ArgumentNullException("form"); } if (modelLanguage == null) { throw new ArgumentNullException("modelLanguage"); } _form = form; _modelLang = modelLanguage; }
protected override bool ProcessSection(IHttpRequest request, IHttpResponse response, IHttpSession session) { if (request.UriParts.Length == 1) { PermissionDeniedMessage denied; var msg = Connections.SendAndReceive <ChannelListMessage> ( new RequestChannelListMessage(), session, out denied); if (denied != null) { WriteAndFlush(response, "{ \"error\": \"Permission denied\" }"); return(true); } WriteAndFlush(response, JsonConvert.SerializeObject(new { DefaultChannel = msg.DefaultChannelId, Channels = msg.Channels.RunQuery(request.QueryString) })); } else if (request.UriParts.Length == 2) { /*if (request.Method.ToLower() != "post") * return false;*/ IHttpInput input = (request.Method.ToLower() == "post") ? request.Form : request.QueryString; int channelId; switch (request.UriParts[1]) { case "delete": case "edit": { if (!request.TryGetItemId(out channelId)) { WriteAndFlush(response, "{ \"error\": \"Invalid channel ID\" }"); return(true); } return(SaveOrUpdateChannel(session, response, input, channelId, (request.UriParts[1] == "delete"))); } case "new": return(SaveOrUpdateChannel(session, response, input, 0, false)); } } else { return(false); } return(true); }
protected override bool ProcessSection(IHttpRequest request, IHttpResponse response, IHttpSession session) { IHttpInput input = (request.Method.ToLower() == "post") ? request.Form : request.QueryString; /*if (request.Method.ToLower() != "post") * return false;*/ if (!input.Contains("username") || !input.Contains("password")) { WriteAndFlush(response, "{ \"error\": \"Invalid request\" }"); return(true); } var result = Connections.SendAndReceive <LoginResultMessage> ( new LoginMessage { Username = input["username"].Value, Password = input["password"].Value }, session); if (!result.Result.Succeeded) { WriteAndFlush(response, JsonConvert.SerializeObject(new { result.Result, SessionId = session.Id })); } else { var pmsg = Connections.Receive <PermissionsMessage> (session); if (pmsg.Permissions.CheckPermission(PermissionName.AdminPanel)) { session["loggedIn"] = true; Connections.SaveSession(session); WriteAndFlush(response, JsonConvert.SerializeObject(new { result.Result, SessionId = session.Id, pmsg.Permissions })); } else { WriteAndFlush(response, "{ \"error\": \"Insufficient permissions\" }"); } } return(true); }
public static IEnumerable <T> RunQuery <T> (this IEnumerable <T> self, IHttpInput query) { if (self == null) { throw new ArgumentNullException("self"); } if (query == null) { throw new ArgumentNullException("query"); } foreach (HttpInputItem input in query.Where(i => i.Value != null)) { switch (input.Name) { case "$skip": { int skip; if (Int32.TryParse(input.Value, out skip)) { self = self.Skip(skip); } break; } case "$top": { int top; if (Int32.TryParse(input.Value, out top)) { self = self.Take(top); } break; } } } return(self); }
/// <summary> /// Recursive function that will go through an xml element and store it's content /// to the form item. /// </summary> /// <param name="item">(parent) Item in form that content should be added to.</param> /// <param name="node">Node that should be parsed.</param> public void TraverseNode(IHttpInput item, XmlNode node) { // Add text node content to previous item if (node.Name == "#text") { HttpInputItem formItem = item as HttpInputItem; if (formItem != null) { formItem.Add(node.InnerText.Trim()); return; } } string name = node.Name.ToLower(); item.Add(name, node.Value); IHttpInput myItem = item[name]; if (node.Attributes != null) foreach (XmlAttribute attribute in node.Attributes) myItem.Add(attribute.Name.ToLower(), attribute.Value); foreach (XmlNode childNode in node.ChildNodes) TraverseNode(myItem, childNode); }
/// <summary> /// /// </summary> /// <param name="form">form that validation should be made on.</param> public FormValidator(IHttpInput form) : this(form, new NameValueCollection()) { }
private static void Add(IHttpInput input, string name, string value, Encoding contentEncoding) { input.Add(HttpUtility.UrlDecode(name, contentEncoding), HttpUtility.UrlDecode(value, contentEncoding)); }
internal void SetForm(HttpInput form) { _form = form; }
internal void SetQueryString(HttpInput query) { _query = query; }
/// <summary>Initialises the class to hold a value either from a post request or a querystring request</summary> public HttpParam(IHttpInput form, IHttpInput query) { _form = form; _query = query; }
private static void Add(IHttpInput input, string name, string value) { input.Add(HttpUtility.UrlDecode(name), HttpUtility.UrlDecode(value)); }
public static bool ContainsAndNotNull(this IHttpInput self, params string[] fieldNames) { return(fieldNames.All(n => self.Contains(n) && self[n].Value != null)); }
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; }
/// <summary> /// Switch to a new http input. /// </summary> /// <param name="form">form to use validation for now</param> /// <param name="modelLanguage">language for the validation</param> public void SetForm(IHttpInput form, ILanguageNode modelLanguage) { if (form == null) throw new ArgumentNullException("form"); if (modelLanguage == null) throw new ArgumentNullException("modelLanguage"); _form = form; _modelLang = modelLanguage; }
/// <summary> /// Switch to a new http input. /// </summary> /// <param name="form">form to use validation for now</param> public void SetForm(IHttpInput form) { if (form == null) throw new ArgumentNullException("form"); _form = form; }
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); }