public void ProcessRequest(HttpContext context) { string json; try { var requestBody = context.Request.Form["RequestBody"]; var requestParams = API.GetAuthRequestParams(requestBody); var repo = new Repository(); if (repo.HaveAuth(requestParams.NetworkID, requestParams.Nick, requestParams.Username, requestParams.Host)) { json = JsonConvert.SerializeObject(new { success = true, alreadyAuthenticated = true }); } else { // Create a new auth record for the user, give him the UID for the web Auth auth = new Auth { FKNetworkID = requestParams.NetworkID, Nick = requestParams.Nick, Username = requestParams.Username, Host = requestParams.Host, SUID = Utils.Get32ByteUID(), DateIssued = DateTime.UtcNow }; repo.AddAuth(auth); repo.SaveChanges(); json = JsonConvert.SerializeObject(new { success = true, ID = auth.AuthID, SUID = auth.SUID }); } } catch (Exception ex) { json = JsonConvert.SerializeObject(new { success = false, error = "There was an exception: " + ex.Message }); } SetNoCaching(context); context.Response.ContentType = "text/json"; context.Response.Write(json); }