public async Task <RecoveryResp> Handle(RecoverAccountByEmailCommand request, CancellationToken cancellationToken) { var response = new RecoveryResp { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { var user = await _userManager.FindByEmailAsync(request.Email); var token = await _userManager.GeneratePasswordResetTokenAsync(user); string ecodedToken = CustomEncoder.Base64Encode(token); await RecoveryMail(request.Email, ecodedToken); response.Status.IsSuccessful = true; response.Status.Message.FriendlyMessage = "Link to reset password has been sent to your email"; return(response); } catch (Exception ex) { response.Status.Message.FriendlyMessage = "Unable to process request"; response.Status.Message.TechnicalMessage = ex.ToString(); return(response); } }
public async Task <Response> GetForm(string formId) { return(new DataResponse <Form>() { Data = await GetFormComplete(CustomEncoder.decode(formId)), Success = true }); }
public async Task <Response> GetForm(int formId) { var form = await GetFormComplete(formId); form.EncodedFormId = CustomEncoder.encode(formId); return(new DataResponse <Form>() { Data = form, Success = true }); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var encoder = new CustomEncoder(); var customContent = await output.GetChildContentAsync(encoder); // Note this is very unsafe. Should always post-process content that may not be fully HTML encoded before // writing it into a response. Here for example, could pass SetContent() a string and that would be // HTML encoded later. output.PreContent .SetHtmlContent("Custom encoder: ") .AppendHtml(customContent) .AppendHtml("<br />"); }
public async Task <RecoveryResp> Handle(ChangePasswordCommand request, CancellationToken cancellationToken) { var response = new RecoveryResp { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { var user = await _userManager.FindByEmailAsync(request.Email); if (user != null) { var decodedToken = CustomEncoder.Base64Decode(request.Token); var passChanged = await _userManager.ResetPasswordAsync(user, decodedToken, request.NewPassword); if (!passChanged.Succeeded) { response.Status.Message.FriendlyMessage = passChanged.Errors.FirstOrDefault().Description; return(response); } user.IsQuestionTime = false; user.EnableAt = DateTime.UtcNow.Subtract(TimeSpan.FromDays(1)); user.NextPasswordChangeDate = DateTime.UtcNow.AddDays(_dataContext.ScrewIdentifierGrid.FirstOrDefault(r => r.Module == (int)Modules.CENTRAL)?.PasswordUpdateCycle ?? 365); var updated = await _userManager.UpdateAsync(user); if (!updated.Succeeded) { response.Status.Message.FriendlyMessage = updated.Errors.FirstOrDefault().Description; return(response); } await RecoveryMail(request.Email); } else { response.Status.Message.FriendlyMessage = "Unidentified Email"; return(response); } response.Status.IsSuccessful = true; response.Status.Message.FriendlyMessage = "Password has successfully been changed"; return(response); } catch (Exception ex) { response.Status.Message.FriendlyMessage = "Unable to process request"; response.Status.Message.TechnicalMessage = ex.ToString(); return(response); } }
public CustomEncoderFactory() { encoder = new CustomEncoder(); }
public void GivenAnEncoder() { Encoder = new CustomEncoder(); }
public async Task<List<LeagueTableItem>> ScrapeBoldLeagueTable(string webAddress, bool useProperNames) { try { //string responseBody = await client.GetStringAsync(@"http:\\" + webAddress); var response = await client.GetByteArrayAsync(@"http:\\" + webAddress); Encoding enc = new CustomEncoder(); string responseBody = enc.GetString(response, 0, response.Length - 1); List<LeagueTableItem> filteredResult = FilterLeagueTableItems(responseBody, "OB", useProperNames); return filteredResult; } catch (HttpRequestException e) { Debug.WriteLine("ScrapeBoldLeagueTable"); return null; } }
private List<MatchItem> FilterMatchItemsSuperliga(string httpResult, int noOfItemsToGet, string teamToSearchFor, bool useProperNames) { HtmlDocument htmlSnippet = new HtmlDocument(); Encoding enc = new CustomEncoder(); htmlSnippet.LoadHtml(httpResult); List<MatchItem> listOfNewsToReturn = new List<MatchItem>(); List<HtmlNode> newsHolder = htmlSnippet.DocumentNode.Descendants("div"). FirstOrDefault(div => div.GetAttributeValue("class", "").Contains("col2")) .Descendants() .Where(html => html.OriginalName == "div" && html.GetAttributeValue("class", "").Contains("note") || html.OriginalName == "table" && html.GetAttributeValue("class", "").Contains("matchprogramtable")) .ToList(); int i = 0; while (i <= newsHolder.Count() - 2) { if (i % 2 == 0) { try { //get node HtmlNode note = newsHolder[i]; HtmlNode matchprogramtable = newsHolder[i + 1]; //Harvest needed information: date, title, url, id string dateRaw = note.FirstChild.InnerText.Trim(); DateTime date = BoldHelpers.FormatDateTime(dateRaw.ToLower().Replace("den ", "").Replace(" i", string.Empty).Trim(), true); string isSuperliga = note.Descendants("a").FirstOrDefault().InnerText.Trim(); string titleRaw = matchprogramtable.Descendants("td").Where(td => td.GetAttributeValue("class", "").Contains("col1")).FirstOrDefault().Descendants("a").FirstOrDefault().InnerText.Replace("Vs.", " - ").RemoveNewLineTag().RemoveTabTag(); string score = string.Empty; if (matchprogramtable.Descendants("td").Where(td => td.GetAttributeValue("class", "").Contains("col2")).FirstOrDefault().Descendants("a").FirstOrDefault() != null) { score = matchprogramtable.Descendants("td").Where(td => td.GetAttributeValue("class", "").Contains("col2")).FirstOrDefault().Descendants("a").FirstOrDefault().InnerText.RemoveNewLineTag().RemoveTabTag(); } string lol = score; string homeTeam = BoldHelpers.FormatHomeTeam(titleRaw); string awayTeam = BoldHelpers.FormatAwayTeam(titleRaw); homeTeam = BoldHelpers.FormatClubName(homeTeam, useProperNames); awayTeam = BoldHelpers.FormatClubName(awayTeam, useProperNames); bool isHomeMatch = BoldHelpers.isHomeTeam(teamToSearchFor, homeTeam); //string urlRaw = matchprogramtable.Descendants("a").FirstOrDefault().GetAttributeValue("href", "123456"); //string url = HoldNytHelpers.FormatUrl(urlRaw); string idRaw = matchprogramtable.Descendants("a").FirstOrDefault().GetAttributeValue("href", "123456"); ////string sourceRaw = node.Descendants("div").Where(div => div.GetAttributeValue("class", "").Contains("news_media")).FirstOrDefault().Descendants("span").FirstOrDefault().GetAttributeValue("class", string.Empty); ////string source = HoldNytHelpers.SourceFormat(sourceRaw); ////MatchItem item = new MatchItem(title, url, date, id, source); MatchItem item = new MatchItem(homeTeam, awayTeam, date, isHomeMatch, idRaw, score); listOfNewsToReturn.Add(item); } catch(Exception e) { Debug.WriteLine("FilterMatchItemsSuperliga: " + e); } } i = i + 2; } return listOfNewsToReturn; }
public async Task<List<MatchItem>> ScrapeBoldSuperligaMatchSchedule(string webAddress, bool useProperNames) { try { var response = await client.GetByteArrayAsync(@"http:\\" + webAddress); Encoding enc = new CustomEncoder(); string responseBody = enc.GetString(response, 0, response.Length - 1); List<MatchItem> filteredResult = FilterMatchItemsSuperliga(responseBody, 0, "OB", useProperNames); return filteredResult; } catch (HttpRequestException e) { Debug.WriteLine("ScrapeBoldSuperligaMatchSchedule: " + e); return null; } }