public static string GetUserEmail(HttpContext httpContext, CookieFailKeyInfo keyInfo, AppSettings appSettings) { var assignments = AvailableAssignmentsHelper.GetAvailableAssignments(httpContext, null); for (int assignmentIndex = 0; assignmentIndex < assignments.Count; assignmentIndex++) { var currentAssignment = assignments[assignmentIndex]; if (currentAssignment != null) { var assignmentDetail = AssignmentDetailHelper.GetAssignmentDetail(httpContext, keyInfo, appSettings, currentAssignment); if (assignmentDetail != null) { var matchingPairs = assignmentDetail.InterestsValues.Where(pair => pair.Key == "login").ToList(); if (matchingPairs.Count > 0) { // We have found email return(matchingPairs[0].Value); } } } assignmentIndex++; } return(string.Empty); }
public static AssignmentDetail GetAssignmentDetail(HttpContext httpContext, CookieFailKeyInfo cookieFailKeyInfo, AppSettings appSettings, Assignment item) { string key = ""; if (cookieFailKeyInfo.IsVaild) { key = cookieFailKeyInfo.Key; var tmpUrl = cookieFailKeyInfo.AvailableAssignmentsUrl; } else { byte[] cookieData; if (httpContext.Session.TryGetValue("Session-Cookie", out cookieData)) { key = System.Text.Encoding.UTF8.GetString(cookieData); } } var cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", key)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { var assignment = GetAssignmentDetailFromUrl(handler, item, appSettings.WebSiteUrl); return(assignment); } }
public ActionResult Post([FromForm] string key, [FromForm] string comment, [FromForm] string password, [FromForm] string cookieFailKey = null) { var keyInfo = new CookieFailKeyInfo(cookieFailKey); List <Assignment> list = AvailableAssignmentsHelper.GetAvailableAssignments(this.HttpContext, keyInfo); var item = list.FirstOrDefault(a => a.Id == key); if (item == null) { return(NotFound()); } var assignment = AssignmentDetailHelper.GetAssignmentDetail(HttpContext, keyInfo, _appSettings, item); if (assignment == null) { return(NotFound()); } string sessionKey = ""; if (keyInfo.IsVaild) { sessionKey = keyInfo.Key; var tmpUrl = keyInfo.AvailableAssignmentsUrl; } else { byte[] cookieData; if (HttpContext.Session.TryGetValue("Session-Cookie", out cookieData)) { sessionKey = System.Text.Encoding.UTF8.GetString(cookieData); } else { return(this.Unauthorized()); } } var cookieContainer = new CookieContainer(); cookieContainer.Add(new System.Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", sessionKey)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { AssignmentDetailHelper.SubmitInterestOfAssignment(handler, assignment, comment, password); return(this.Ok()); } }
//[ResponseCache(VaryByQueryKeys = new[] { "key" }, Duration = 60)] public JsonResult Get(string key, string cookieFailKey = null) { try { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); var keyInfo = new CookieFailKeyInfo(cookieFailKey); List <Assignment> list = AvailableAssignmentsHelper.GetAvailableAssignments(this.HttpContext, keyInfo); var item = list.FirstOrDefault(a => a.Id == key); if (item == null) { return(Json(null)); } var assignment = AssignmentDetailHelper.GetAssignmentDetail(HttpContext, keyInfo, _appSettings, item); if (assignment == null) { return(Json(null)); } return(Json(new AssignmentDetail { Id = item.Id, Name = item.Name, Category = item.Category, Date = item.Date, Area = item.Area, Description = assignment.Description, Time = assignment.Time, ContactInfo = assignment.ContactInfo, MeetupTime = assignment.MeetupTime, MeetupPlace = assignment.MeetupPlace, LastRequestDate = assignment.LastRequestDate, GoogleCalendarEventUrl = assignment.GoogleCalendarEventUrl, WantedNumberOfPeople = assignment.WantedNumberOfPeople, CurrentNumberOfPeople = assignment.CurrentNumberOfPeople, InterestsFormUrl = assignment.InterestsFormUrl, InterestsValues = assignment.InterestsValues })); } catch (System.Exception ex) { return(Json(new Assignment { Name = ex.Message })); } }
public bool Get([FromQuery] string cookieFailKey) { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); try { var keyInfo = new CookieFailKeyInfo(cookieFailKey); var list = AvailableAssignmentsHelper.GetAvailableAssignments(HttpContext, keyInfo); return(list.Count > 0); } catch (System.Exception) { return(false); } }
public static NavigationInfo GetNavigation(HttpContext httpContext, CookieFailKeyInfo cookieFailKeyInfo) { if (!cookieFailKeyInfo.IsVaild) { byte[] cookieData; if (httpContext.Session.TryGetValue("MainNavigation", out cookieData)) { var content = System.Text.Encoding.UTF8.GetString(cookieData); var jArray = Newtonsoft.Json.JsonConvert.DeserializeObject(content) as Newtonsoft.Json.Linq.JObject; var navigationInfo = jArray.ToObject <NavigationInfo>(); if (navigationInfo != null) { return(navigationInfo); } } return(null); } else { var cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", cookieFailKeyInfo.Key)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { HttpClient client = new HttpClient(handler); using (var response = client.GetAsync("http://volontar.polisen.se/" + cookieFailKeyInfo.AvailableAssignmentsUrl).Result) { using (var responseContent = response.Content) { var content = responseContent.ReadAsStringAsync().Result; if (!LoginHelper.IsLoginContent(content)) { return(null); } else { return(new NavigationInfo(content)); } } } } } }
public MyAssignmentsInfo Get(string cookieFailKey = null) { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); var keyInfo = new CookieFailKeyInfo(cookieFailKey); try { return(MyAssignmentsHelper.GetMyAssignments(this.HttpContext, keyInfo)); } catch (System.Exception ex) { // TODO: We don't know if we are logged in BUT while debugging we need to be able to check this return(new MyAssignmentsInfo { IsLoggedIn = true, Reservations = new List <Assignment> { new AssignmentDetail { Description = "Unknown Error2: " + ex } } }); } }
public static MyAssignmentsInfo GetMyAssignments(HttpContext httpContext, CookieFailKeyInfo cookieFailKeyInfo) { string key = ""; if (cookieFailKeyInfo.IsVaild) { key = cookieFailKeyInfo.Key; var tmpUrl = cookieFailKeyInfo.AvailableAssignmentsUrl; } else { byte[] cookieData; if (httpContext.Session.TryGetValue("Session-Cookie", out cookieData)) { key = System.Text.Encoding.UTF8.GetString(cookieData); } } var navigationInfo = NavigationHelper.GetNavigation(httpContext, cookieFailKeyInfo); if (navigationInfo == null) { return(new MyAssignmentsInfo { IsLoggedIn = false }); } var cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", key)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { return(GetMyAssignmentsInfoFromUrl(handler, navigationInfo)); } }
private static List <Assignment> GetAvailableAssignmentsFromPortal(CookieFailKeyInfo cookieFailKeyInfo) { var list = new List <Assignment>(); try { var cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", cookieFailKeyInfo.Key)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { HttpClient client = new HttpClient(handler); using (var response = client.GetAsync("http://volontar.polisen.se/" + cookieFailKeyInfo.AvailableAssignmentsUrl).Result) { using (var responseContent = response.Content) { var content = responseContent.ReadAsStringAsync().Result; if (!LoginHelper.IsLoginContent(content)) { return(list); } var availableAssignments = new AvailableAssignmentsInfo(content); list.AddRange(availableAssignments.Assignments); } } } } catch (Exception) { // TODO: Do error handling } return(list); }
public int Get(string cookieFailKey = null) { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); try { var keyInfo = new CookieFailKeyInfo(cookieFailKey); var list = AvailableAssignmentsHelper.GetAvailableAssignments(HttpContext, keyInfo); if (list.Count == 0) { return(1); } else { return(2); } } catch (System.Exception) { return(-2); } }
public static List <Assignment> GetAvailableAssignments(HttpContext httpContext, CookieFailKeyInfo cookieFailKeyInfo) { var list = new List <Assignment>(); try { if (!cookieFailKeyInfo.IsVaild) { list = GetAvailableAssignmentsFromSession(httpContext); } if (list.Count == 0) { list = GetAvailableAssignmentsFromPortal(cookieFailKeyInfo); } } catch (System.Exception) { // TODO: Do error handling } return(list); }
public static List <Assignment> AdvancedFilerItems(List <Assignment> items, AvailableAssignmentFilterSettings filterSettings, HttpContext httpContext, CookieFailKeyInfo cookieKeyInfo, AppSettings appSettings, out int skipCount) { skipCount = 0; List <Assignment> filteredItems = new List <Assignment>(items); var isFilterOnlyAssignmentsThatCanBeBooked = filterSettings.NeverShowSpecTypes.Any(x => x == 0); var isFilterNotOverbookedAssignments = filterSettings.NeverShowSpecTypes.Any(x => x == 1); if (isFilterOnlyAssignmentsThatCanBeBooked || isFilterNotOverbookedAssignments) { // filters out items that we are not interested in var indexesToRemove = new List <int>(); var ourWeekNumber = -1; var hasWeekNumber = false; for (int assignmentIndex = 0; assignmentIndex < items.Count; assignmentIndex++) { var assignment = items[assignmentIndex]; DateTime date; if (DateTime.TryParse(assignment.Date, out date)) { var weekNumber = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); if (hasWeekNumber) { if (ourWeekNumber != weekNumber) { // Only do this for one week at the time, ignore rest (because of performance issues on orginal server) // It takes 30-40 seconds to do this for all assignments at the same time. indexesToRemove.Add(assignmentIndex); continue; } } var details = AssignmentDetailHelper.GetAssignmentDetail(httpContext, cookieKeyInfo, appSettings, assignment); var shouldBeKept = true; if (isFilterOnlyAssignmentsThatCanBeBooked) { shouldBeKept = details.InterestsValues.Count > 0; } if (shouldBeKept && isFilterNotOverbookedAssignments) { int currentNumberOfPeople, wantedNumberOfPeople; if (int.TryParse(details.CurrentNumberOfPeople, out currentNumberOfPeople) && int.TryParse(details.WantedNumberOfPeople, out wantedNumberOfPeople)) { shouldBeKept = currentNumberOfPeople < wantedNumberOfPeople; } } if (shouldBeKept) { if (!hasWeekNumber) { ourWeekNumber = weekNumber; hasWeekNumber = true; } skipCount++; } else { indexesToRemove.Add(assignmentIndex); skipCount++; } // Make some efforts to not DDOS orginal server //System.Threading.Thread.Sleep(10); } } if (indexesToRemove.Count > 0) { indexesToRemove.Reverse(); for (var removeIndex = 0; removeIndex < indexesToRemove.Count; removeIndex++) { var indexToRemove = indexesToRemove[removeIndex]; filteredItems.RemoveAt(indexToRemove); } } } return(filteredItems); }
//[ResponseCache(VaryByHeader = "Cookie", VaryByQueryKeys = new[] { "key" }, Duration = 60)] public AvailableAssignmentsResult Get(string key, int startIndex = 0, int nOfItems = -1, string filterAlwaysShowTypes = null, string filterNeverShowTypes = null, string filterHideWorkDayTypes = null, string filterHideWeekendTypes = null, string filterNeverShowAreas = null, string filterAlwaysShowAreas = null, string filterNeverShowSpecTypes = null, string cookieFailKey = null) { // Spara svaret i 5 minuter (detta gör att sidor laddar snabbare när vi går tillbaka från att se detaljer för ett uppdrag) this.Response.Headers.Add("Cache-Control", "max-age=300"); var keyInfo = new CookieFailKeyInfo(cookieFailKey); var totalNofItems = 0; // TODO: 1. Sanity checking // TODO: 2. Validate login List <Assignment> list = AvailableAssignmentsHelper.GetAvailableAssignments(this.HttpContext, keyInfo); totalNofItems = list.Count; // filter items var filterNofItems = 0; var filterSettings = AvailableAssignmentsHelper.GetFilterSettings(filterAlwaysShowTypes, filterNeverShowTypes, filterHideWorkDayTypes, filterHideWeekendTypes, filterNeverShowAreas, filterAlwaysShowAreas, filterNeverShowSpecTypes ); list = AvailableAssignmentsHelper.FilerItems(list, filterSettings, HttpContext, _appSettings); filterNofItems = list.Count; // only get ONE item, if available if (key != null) { list = list.Where(a => a.Id == key).ToList(); } // support paging, start position if (startIndex > 0) { list = list.Skip(startIndex).ToList(); } int skipCount; list = AvailableAssignmentsHelper.AdvancedFilerItems(list, filterSettings, HttpContext, keyInfo, _appSettings, out skipCount); // support paging, number of items if (nOfItems > 0) { list = list.Take(nOfItems).ToList(); } // 3. Return available assignmets var groupedList = list.GroupBy(AvailableAssignmentsHelper.GroupByDay); var nextStartIndex = 0; if (skipCount > 0 && list.Count > 0) { nextStartIndex = skipCount + startIndex; } return(new AvailableAssignmentsResult { NextStartIndex = nextStartIndex, TotalNumberOfItems = totalNofItems, FilteredNofItems = filterNofItems, Items = groupedList.ToArray() }); }
public IActionResult Post([FromForm] string username, [FromForm] string password, [FromForm] string page, [FromForm] string query, [FromForm] bool failedCookieCheck) { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); var successfullLogin = false; string redirectUrl = null; var isSecurePassword = false; string cookieFailKey = ""; var cookieContainer = new CookieContainer(); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { var passwordStatus = LoginHelper.IsPasswordOk(password); var passwordStatusQuery = ""; if (!passwordStatus) { passwordStatusQuery = "?warning=1"; } isSecurePassword = passwordStatus; // TODO: 1. Sanity checking // TODO: 2. Make login request var loginUrl = LoginHelper.GetLoginUrl(handler); var info = LoginHelper.Login(handler, loginUrl, username, password); successfullLogin = info.Status; if (info.Status) { var cookies = cookieContainer.GetCookies(new System.Uri("http://volontar.polisen.se")); foreach (Cookie cookie in cookies) { if (cookie.Name == "PHPSESSID") { HttpContext.Session.Set("Session-Cookie", System.Text.Encoding.UTF8.GetBytes(cookie.Value)); if (failedCookieCheck) { cookieFailKey = CookieFailKeyInfo.ToKey(cookie.Value, info.MainNavigation.AvailableAssignmentsUrl); } } } var availableAssignments = Newtonsoft.Json.JsonConvert.SerializeObject(info.AvailableAssignments.Assignments.ToArray()); HttpContext.Session.Set("AvailableAssignments", System.Text.Encoding.UTF8.GetBytes(availableAssignments)); var mainNavigation = Newtonsoft.Json.JsonConvert.SerializeObject(info.MainNavigation); HttpContext.Session.Set("MainNavigation", System.Text.Encoding.UTF8.GetBytes(mainNavigation)); switch (page) { case "assignment": if (query != null && query.IndexOf('?') == 0) { // lookup assignment var assignmentId = query.Replace("?key=", ""); var assignment = info.AvailableAssignments.Assignments.FirstOrDefault(a => a.Id == assignmentId); if (assignment == null) { // Assignment can't be found, go to start page instead redirectUrl = _appSettings.WebSiteUrl + "/restricted/" + passwordStatusQuery; //return this.Redirect(_appSettings.WebSiteUrl + "/restricted/" + passwordStatusQuery); } else { // go to assignment redirectUrl = _appSettings.WebSiteUrl + "/restricted/assignment/?key=" + assignmentId + passwordStatusQuery.Replace('?', '&'); //return this.Redirect(_appSettings.WebSiteUrl + "/restricted/assignment/?key=" + assignmentId + passwordStatusQuery.Replace('?', '&')); } } else { redirectUrl = _appSettings.WebSiteUrl + "/restricted/available-assignments/" + passwordStatusQuery; //return this.Redirect(_appSettings.WebSiteUrl + "/restricted/available-assignments/" + passwordStatusQuery); } break; case "available-assignments": redirectUrl = _appSettings.WebSiteUrl + "/restricted/available-assignments/" + passwordStatusQuery; //return this.Redirect(_appSettings.WebSiteUrl + "/restricted/available-assignments/" + passwordStatusQuery); break; default: redirectUrl = _appSettings.WebSiteUrl + "/restricted/" + passwordStatusQuery; //return this.Redirect(_appSettings.WebSiteUrl + "/restricted/" + passwordStatusQuery); break; } } else { redirectUrl = _appSettings.WebSiteUrl + "/?warning=2"; //return this.Redirect(_appSettings.WebSiteUrl + "/?warning=2"); } // TODO: 3. If no valid login, return false // TODO: 4a. Add session info // TODO: 4b. return true; } return(Json(new LoginResult { IsSuccess = successfullLogin, IsWeakPassword = !isSecurePassword, RedirectUrl = redirectUrl, CookieFailKey = cookieFailKey })); }
public ReportResult Post( [FromForm] bool anonymous, [FromForm] string assignmentOrDate, [FromForm] int areaIndex, [FromForm] string feedback1, [FromForm] string feedback2, [FromForm] string feedback3, string cookieFailKey = null) { ReportResult reportResult = new ReportResult(); var keyInfo = new CookieFailKeyInfo(cookieFailKey); var navigationInfo = NavigationHelper.GetNavigation(HttpContext, keyInfo); string key = ""; if (keyInfo.IsVaild) { key = keyInfo.Key; var tmpUrl = keyInfo.AvailableAssignmentsUrl; } else { byte[] cookieData; if (HttpContext.Session.TryGetValue("Session-Cookie", out cookieData)) { key = System.Text.Encoding.UTF8.GetString(cookieData); } else { return(reportResult); } } var cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", key)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { if (navigationInfo != null) { var reportUrl = MyAssignmentReportHelper.GetReportUrl(handler, navigationInfo, areaIndex); if (string.IsNullOrEmpty(reportUrl)) { return(reportResult); } var reportInfo = MyAssignmentReportHelper.GetReportActionUrlAndUserName(handler, reportUrl); var actionUrl = reportInfo.ActionUrl; if (string.IsNullOrEmpty(actionUrl)) { return(reportResult); } var name = ""; var email = ""; if (!anonymous) { name = reportInfo.UserFullName ?? ""; email = MyAssignmentReportHelper.GetUserEmail(HttpContext, keyInfo, _appSettings) ?? ""; } else { name = "Användaren har valt att vara anonym"; } //reportResult.Name = name; //reportResult.Email = email; var result = MyAssignmentReportHelper.PostReport( handler, actionUrl, name, email, assignmentOrDate, feedback1, feedback2, feedback3 ); reportResult.IsSuccess = result; return(reportResult); } } return(reportResult); }
public IActionResult Post([FromForm] string currentPassword, [FromForm] string newPassword, [FromForm] string cookieFailKey = null) { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); var keyInfo = new CookieFailKeyInfo(cookieFailKey); string step1Url = ""; string step2Url = ""; var step1InterestsValues = new List <KeyValuePair <string, string> >(); var step2InterestsValues = new List <KeyValuePair <string, string> >(); ChangePasswordResult info = new ChangePasswordResult(); var isSecurePassword = false; var newPasswordStatus = LoginHelper.IsPasswordOk(newPassword); if (!newPasswordStatus) { info.IsWeakPassword = !newPasswordStatus; info.Warning = 1; return(Json(info)); } isSecurePassword = newPasswordStatus; var navigationInfo = NavigationHelper.GetNavigation(HttpContext, keyInfo); string key = ""; if (keyInfo.IsVaild) { key = keyInfo.Key; var tmpUrl = keyInfo.AvailableAssignmentsUrl; } else { byte[] cookieData; if (HttpContext.Session.TryGetValue("Session-Cookie", out cookieData)) { key = System.Text.Encoding.UTF8.GetString(cookieData); } else { info.Warning = 3; return(Json(info)); } } var cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", key)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { if (navigationInfo != null) { // TODO: 3. If no valid login, return false // TODO: 4a. Add session info // TODO: 4b. return true; HttpClient client = new HttpClient(handler); using (var response = client.GetAsync("http://volontar.polisen.se/" + navigationInfo.ChangePasswordUrl).Result) { using (var responseContent = response.Content) { var step01Content = responseContent.ReadAsStringAsync().Result; // action="([^"]+)" var urlMatch = Regex.Match(step01Content, "action=\"(?<url>[^\"]+)\""); if (urlMatch.Success) { var urlGroup = urlMatch.Groups["url"]; if (urlGroup.Success) { step1Url = "http://volontar.polisen.se/" + urlGroup.Value.Replace("../", ""); } } // name="([^"]+)" value="([^"]+)" var nameAndValuePairsMatch = Regex.Matches(step01Content, "name=\"(?<name>[^\"]+)\" value=\"(?<value>[^\"]+)\""); foreach (Match nameAndValuePairMatch in nameAndValuePairsMatch) { if (nameAndValuePairMatch.Success) { var nameGroup = nameAndValuePairMatch.Groups["name"]; var valueGroup = nameAndValuePairMatch.Groups["value"]; if (nameGroup.Success && valueGroup.Success) { step1InterestsValues.Add(new KeyValuePair <string, string>(nameGroup.Value, valueGroup.Value)); } } } if (step1InterestsValues.Count > 0) { step1InterestsValues.Add(new KeyValuePair <string, string>("password", currentPassword)); step1InterestsValues.Add(new KeyValuePair <string, string>("submit_19_12", "Gå+vidare")); } } } if (string.IsNullOrEmpty(step1Url) || step1InterestsValues.Count < 3) { info.Warning = 4; return(Json(info)); } // Verify current password AND get values for step 2 var step1Content = new FormUrlEncodedContent(step1InterestsValues); using (var response = client.PostAsync(step1Url, step1Content).Result) { using (var responseContent = response.Content) { var step02Content = responseContent.ReadAsStringAsync().Result; // action="([^"]+)" var urlMatch = Regex.Match(step02Content, "action=\"(?<url>[^\"]+)\""); if (urlMatch.Success) { var urlGroup = urlMatch.Groups["url"]; if (urlGroup.Success) { step2Url = "http://volontar.polisen.se/" + urlGroup.Value.Replace("../", ""); } } // name="([^"]+)" value="([^"]+)" var nameAndValuePairsMatch = Regex.Matches(step02Content, "name=\"(?<name>[^\"]+)\" value=\"(?<value>[^\"]+)\""); foreach (Match nameAndValuePairMatch in nameAndValuePairsMatch) { if (nameAndValuePairMatch.Success) { var nameGroup = nameAndValuePairMatch.Groups["name"]; var valueGroup = nameAndValuePairMatch.Groups["value"]; if (nameGroup.Success && valueGroup.Success) { step2InterestsValues.Add(new KeyValuePair <string, string>(nameGroup.Value, valueGroup.Value)); } } } if (step2InterestsValues.Count > 0) { step2InterestsValues.Add(new KeyValuePair <string, string>("cont_cont/password", newPassword)); step2InterestsValues.Add(new KeyValuePair <string, string>("submit_28_2", "Byt+lösenord")); } } } if (string.IsNullOrEmpty(step2Url) || step2InterestsValues.Count < 3) { info.Warning = 4; return(Json(info)); } if (step1Url == step2Url) { // Invalid current password info.Warning = 6; return(Json(info)); } // Change password var step2Content = new FormUrlEncodedContent(step2InterestsValues); using (var response = client.PostAsync(step2Url, step2Content).Result) { using (var responseContent = response.Content) { var step03Content = responseContent.ReadAsStringAsync().Result; // action="([^"]+)" var urlMatch = Regex.Match(step03Content, "Ditt lösenord är nu uppdaterat"); if (urlMatch.Success) { info.IsSuccess = true; return(Json(info)); } else { info.Warning = 4; return(Json(info)); } } } } else { info.Warning = 3; return(Json(info)); } } }