public void Email_Disabled_Post_Disabled_No_Captcha() { var contact = ContactModelBuilder.GetContactNoCaptcha(); var contactSettings = new ContactSettings { EmailSettings = EmailSettingsBuilder.GetDisabled(), PostSettings = PostSettingsBuilder.GetDisabled(), RecaptchaSettings = RecaptchaSettingsBuilder.GetDisabled() }; var result = contactService.Submit(contact, contactSettings); Assert.True(result.Success); }
public ContactResult FunctionHandler(ContactModel contact, ILambdaContext context) { var settings = GetSettings(); settings.RecaptchaSettings.RecaptchaResponse = contact.RecaptchaResponse; var contactService = new ContactFormService(new LoggerAdapter(context.Logger)); return(contactService.Submit(contact, settings)); }
public IActionResult IndexForm(ContactModel contact) { if (contactSettings.RecaptchaSettings != null && contactSettings.RecaptchaSettings.Enabled && !string.IsNullOrEmpty(contactSettings.RecaptchaSettings.RecaptchaKey)) { contactSettings.RecaptchaSettings.RecaptchaResponse = contact.RecaptchaResponse = HttpContext.Request.Form["g-recaptcha-response"].ToString(); } var result = contactFormService.Submit(contact, contactSettings); if (!string.IsNullOrEmpty(contactSettings.PostSettings.RedirectURL) && contactSettings.PostSettings.RedirectSeconds == -1) { return(new RedirectResult(string.Format(contactSettings.PostSettings.RedirectURL, result.Success ? "1" : "0"))); } else { return new ContentResult { Content = contactFormService.GetResultHTML(result, contactSettings), ContentType = "text/html", StatusCode = 200 } }; }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "options", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext context) { log.LogInformation("C# HTTP trigger function processed a request."); ContactModel contact; var isJson = req.ContentType.StartsWith("application/json"); if (isJson) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); contact = JsonConvert.DeserializeObject <ContactModel>(requestBody); } else { contact = new ContactModel { ContactName = req.Form["ContactName"], Email = req.Form["Email"], Phone = req.Form["Phone"], Subject = req.Form["Subject"], Category = req.Form["Category"], Message = req.Form["Message"], RecaptchaResponse = req.Form["g-recaptcha-response"] }; } if (contact == null) { return(new BadRequestObjectResult("Please pass a contact form data")); } else { // Get settings var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); var contactSettings = new ContactSettings(); config.GetSection("ContactSettings").Bind(contactSettings); var contactService = new ContactFormService(log); contactSettings.RecaptchaSettings.RecaptchaResponse = contact.RecaptchaResponse; var result = contactService.Submit(contact, contactSettings); if (isJson) { return((ActionResult) new OkObjectResult(result)); } else { // Return 'text/html' if (!string.IsNullOrEmpty(contactSettings.PostSettings.RedirectURL) && contactSettings.PostSettings.RedirectSeconds == -1) { return(new RedirectResult(string.Format(contactSettings.PostSettings.RedirectURL, result.Success ? "1" : "0"))); } else { return new ContentResult { Content = contactService.GetResultHTML(result, contactSettings), ContentType = "text/html", StatusCode = 200 } }; } } } }