private byte[] CreateAccount(string resource, IOSHttpRequest httpRequest, Dictionary <string, object> request) { string first = String.Empty; string last = String.Empty; string email = String.Empty; string password = String.Empty; string password2 = String.Empty; string avatar = string.Empty; if (request.ContainsKey("first") && WebAppUtils.IsValidName(request["first"].ToString())) { first = request["first"].ToString(); } if (request.ContainsKey("last") && WebAppUtils.IsValidName(request["last"].ToString())) { last = request["last"].ToString(); } if (request.ContainsKey("email") && WebAppUtils.IsValidEmail(request["email"].ToString())) { email = request["email"].ToString(); } if (request.ContainsKey("password")) { password = request["password"].ToString(); } if (request.ContainsKey("password2")) { password2 = request["password2"].ToString(); } if (request.ContainsKey("avatar")) { avatar = request["avatar"].ToString(); } Request req = RequestFactory.CreateRequest(resource, httpRequest); Diva.Wifi.Environment env = new Diva.Wifi.Environment(req); string result = m_WebApp.Services.NewAccountPostRequest(env, first, last, email, password, password2, avatar); return(WebAppUtils.StringToBytes(result)); }
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // It's a POST, so we need to read the data on the stream, the lines after the blank line StreamReader sr = new StreamReader(requestData); string body = sr.ReadToEnd(); sr.Close(); body = body.Trim(); httpResponse.ContentType = "text/html"; string resource = GetParam(path); //m_log.DebugFormat("[XXX]: query String: {0}; resource: {1}", body, resource); try { // Here the data on the stream is transformed into a nice dictionary of keys & values Dictionary <string, object> postdata = ServerUtils.ParseQueryString(body); Request req = RequestFactory.CreateRequest(resource, httpRequest, Localization.GetLanguageInfo(httpRequest.Headers.Get("accept-language"))); Environment env = new Environment(req); string result = string.Empty; if (resource.Equals("/") || resource.Equals(string.Empty)) { // The client invoked /wifi/admin/users/ string terms = String.Empty; if (postdata.ContainsKey("terms")) { terms = postdata["terms"].ToString(); } result = m_WebApp.Services.UserSearchPostRequest(env, terms); } else if (resource.StartsWith("/edit")) { // The client invoked /wifi/admin/users/edit, possibly with the UUID parameter after UUID userID = UUID.Zero; string[] pars = SplitParams(path); if ((pars.Length >= 2) && UUID.TryParse(pars[1], out userID)) { // Indeed the client invoked /wifi/admin/users/edit/<uuid>, and we got it already in userID (above) string form = string.Empty; if (postdata.ContainsKey("form")) { form = postdata["form"].ToString(); } if (form == "1") { string first = string.Empty, last = string.Empty, email = string.Empty, title = string.Empty; int level = 0, flags = 0; if (postdata.ContainsKey("first") && WebAppUtils.IsValidName(postdata["first"].ToString())) { first = postdata["first"].ToString(); } if (postdata.ContainsKey("last") && WebAppUtils.IsValidName(postdata["last"].ToString())) { last = postdata["last"].ToString(); } if (postdata.ContainsKey("email") && WebAppUtils.IsValidEmail(postdata["email"].ToString())) { email = postdata["email"].ToString(); } if (postdata.ContainsKey("title")) { title = postdata["title"].ToString(); } if (postdata.ContainsKey("level")) { Int32.TryParse(postdata["level"].ToString(), out level); } if (postdata.ContainsKey("flags")) { Int32.TryParse(postdata["flags"].ToString(), out flags); } result = m_WebApp.Services.UserEditPostRequest(env, userID, first, last, email, level, flags, title); } else if (form == "2") { string password = string.Empty; if (postdata.ContainsKey("password")) { password = postdata["password"].ToString(); result = m_WebApp.Services.UserEditPostRequest(env, userID, password); } } } } else if (resource.StartsWith("/delete")) { // The client invoked /wifi/admin/users/edit, possibly with the UUID parameter after UUID userID = UUID.Zero; string[] pars = SplitParams(path); if ((pars.Length >= 2) && UUID.TryParse(pars[1], out userID)) { // Indeed the client invoked /wifi/admin/users/edit/<uuid>, and we got it already in userID (above) string form = string.Empty; if (postdata.ContainsKey("form")) { form = postdata["form"].ToString(); } if (form == "1") { result = m_WebApp.Services.UserDeletePostRequest(env, userID); } } } return(WebAppUtils.StringToBytes(result)); } catch (Exception e) { m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}", e); } return(WebAppUtils.FailureResult()); }