public void FromXmlTest() { /* * Assume: ToXml(string) is correct. */ var otpContext = new OtpContext(); var xml = XElement.Parse(File.ReadAllText(Data.OtpContextXml)).Elements().ToArray(); // Validate null argument. Assert.Throws <ArgumentNullException>("element", () => otpContext.FromXml(null)); // XML must be same after loading and deserializing it. foreach (var element in xml) { otpContext.FromXml(element); Assert.True(XNode.DeepEquals(element, otpContext.ToXml("Otp"))); } }
public HttpStatusCode ComparePasswords([FromBody] JObject json) { if (json == null) { return(HttpStatusCode.NoContent); } using (var context = new OtpContext(configuration)) { var userSecret = context.AspNetUsers.Where(u => u.Id.Equals(json["userId"].ToString())).First(); var generator = new OtpGenerator(userSecret.Secret, 30, 10, 6, new HmacSha256()); if (generator.GenerateCode().Equals(json["otp"].ToString())) { return(HttpStatusCode.OK); } return(HttpStatusCode.Forbidden); } }
public async Task <IActionResult> GetDay() { var otpContext = OtpContext.FromPrincipal(User); IOperationResult result = null; if (otpContext.TryParse <DayOtpModel>(out var model)) { Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = model.Culture.ToCultureInfo(); result = await _executor .Add <GetDaysOperation, GetDaysOperation.Input>(() => new GetDaysOperation.Input(model.Date, model.Date, User.GetTenantId())) .Add <ParseTemplateOperation, List <Day>, ParseTemplateOperation.Input>(days => new ParseTemplateOperation.Input { Model = days.FirstOrDefault(), TemplateKey = "Day" }) .Add <HtmlToPdfOperation, ParseTemplateOperation.Output, HtmlToPdfOperation.Input>(last => new HtmlToPdfOperation.Input(last.Result)) .Execute(); } if (result?.ResultType == OperationResultType.Succeeded) { return(new FileContentResult(result.GetResult <HtmlToPdfOperation.Output>().Pdf, "application/pdf")); } else { string htmlResult; if (_hostingEnvironment.IsDevelopment()) { htmlResult = result.Error?.ToString(); } else { htmlResult = "Error"; } return(new OkObjectResult(htmlResult)); } }
public VerifyOTPSteps(OtpContext ctx) => this.ctx = ctx;
public RequestOTPSteps(OtpContext ctx) => this.ctx = ctx;
public BackgroundSteps(OtpContext ctx) => this.ctx = ctx;
public OtpRepository(OtpContext otpContext) { this.otpContext = otpContext; }