This commit is contained in:
2018-07-23 19:33:27 +00:00
parent a54087b5a5
commit bdbf4b6316
6 changed files with 92 additions and 19 deletions

View File

@@ -100,7 +100,7 @@
<label class="col-md-4 control-label" for="Send"></label>
<div class="col-md-4">
<div class="g-recaptcha" data-callback="imNotARobot" data-sitekey="6LcH7GUUAAAAAJIDf_JDZolSv__xN6oqr9Dx79zs"></div>
<button id="btnsubmit" type="submit" class="btn btn-info" >Send us your question</button>
<button id="btnsubmit" type="submit" class="btn btn-info" >Send us your question</button>
</div>
</div>
<!-- <div class="row">

View File

@@ -53,8 +53,8 @@ namespace contact.Pages
_configuration.GetSection("GoogleReCaptcha:secret").Value
))
{
//ModelState.AddModelError(string.Empty, "You failed the CAPTCHA, stupid robot. Go play some 1x1 on SFs instead.");
return StatusCode(400);
//Return a fail code that will hopefully take us off the spammers list
return StatusCode(500);
}

View File

@@ -83,7 +83,8 @@
<div class="form-group">
<label class="col-md-4 control-label" for="Send"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-info" >Receive 30 day Activation key</button>
<div class="g-recaptcha" data-callback="imNotARobot" data-sitekey="6LcH7GUUAAAAAJIDf_JDZolSv__xN6oqr9Dx79zs"></div>
<button id="btnsubmit" type="submit" class="btn btn-info" >Receive 30 day Activation key</button>
</div>
</div>
<!-- <div class="row">

View File

@@ -7,6 +7,11 @@ using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using System.Net.Mail;
using System.Net;
//for captcha:
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using Microsoft.Extensions.Configuration;
namespace contact.Pages
{
@@ -17,7 +22,7 @@ namespace contact.Pages
public string Name { get; set; }
[Required]
public string Company { get; set; }
[Required]
[Required]
public string Referrer { get; set; }
[Required, EmailAddress]
public string Email { get; set; }
@@ -30,7 +35,11 @@ namespace contact.Pages
public string Message { get; set; }
[BindProperty]
public RequestFormModel Contact { get; set; }
private readonly IConfiguration _configuration;
public RequestModel(IConfiguration configuration)
{
_configuration = configuration;
}
public ActionResult OnPost()
{
@@ -38,12 +47,16 @@ namespace contact.Pages
{
return Page();
}
//fuck those Russian spammers
if(Contact.Company.ToLowerInvariant()!="google")
SendMail();
if (!ReCaptchaPassed(
Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
_configuration.GetSection("GoogleReCaptcha:secret").Value
))
{
//Return a fail code that will hopefully take us off the spammers list
return StatusCode(500);
}
//TODO: go to a successful submit page on the ayanova site
//return Redirect("/confirm.html");//sample quickie page I made up
SendMail();
return Redirect("https://ayanova.com/confirmed.htm");
}
@@ -100,5 +113,27 @@ namespace contact.Pages
{
Message = "Your contact page.";
}
public static bool ReCaptchaPassed(string gRecaptchaResponse, string secret)
{
HttpClient httpClient = new HttpClient();
var res = httpClient.GetAsync($"https://www.google.com/recaptcha/api/siteverify?secret={secret}&response={gRecaptchaResponse}").Result;
if (res.StatusCode != HttpStatusCode.OK)
{
// logger.LogError("Error while sending request to ReCaptcha");
return false;
}
string JSONres = res.Content.ReadAsStringAsync().Result;
dynamic JSONdata = JObject.Parse(JSONres);
if (JSONdata.success != "true")
{
return false;
}
return true;
}
}
}

View File

@@ -83,7 +83,8 @@
<div class="form-group">
<label class="col-md-4 control-label" for="Send"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-info" >Receive 30 day Lite Activation key</button>
<div class="g-recaptcha" data-callback="imNotARobot" data-sitekey="6LcH7GUUAAAAAJIDf_JDZolSv__xN6oqr9Dx79zs"></div>
<button id="btnsubmit" type="submit" class="btn btn-info" >Receive 30 day Lite Activation key</button>
</div>
</div>
<!-- <div class="row">

View File

@@ -7,6 +7,11 @@ using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using System.Net.Mail;
using System.Net;
//for captcha:
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using Microsoft.Extensions.Configuration;
namespace contact.Pages
{
@@ -17,7 +22,7 @@ namespace contact.Pages
public string Name { get; set; }
[Required]
public string Company { get; set; }
[Required]
[Required]
public string Referrer { get; set; }
[Required, EmailAddress]
public string Email { get; set; }
@@ -30,7 +35,11 @@ namespace contact.Pages
public string Message { get; set; }
[BindProperty]
public RequestFormModel Contact { get; set; }
private readonly IConfiguration _configuration;
public RequestLiteModel(IConfiguration configuration)
{
_configuration = configuration;
}
public ActionResult OnPost()
{
@@ -38,12 +47,17 @@ namespace contact.Pages
{
return Page();
}
//fuck those Russian spammers
if(Contact.Company.ToLowerInvariant()!="google")
SendMail();
if (!ReCaptchaPassed(
Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
_configuration.GetSection("GoogleReCaptcha:secret").Value
))
{
//Return a fail code that will hopefully take us off the spammers list
return StatusCode(500);
}
SendMail();
//TODO: go to a successful submit page on the ayanova site
//return Redirect("/confirm.html");//sample quickie page I made up
return Redirect("https://ayanova.com/confirmed.htm");
}
@@ -100,5 +114,27 @@ namespace contact.Pages
{
Message = "Your contact page.";
}
public static bool ReCaptchaPassed(string gRecaptchaResponse, string secret)
{
HttpClient httpClient = new HttpClient();
var res = httpClient.GetAsync($"https://www.google.com/recaptcha/api/siteverify?secret={secret}&response={gRecaptchaResponse}").Result;
if (res.StatusCode != HttpStatusCode.OK)
{
// logger.LogError("Error while sending request to ReCaptcha");
return false;
}
string JSONres = res.Content.ReadAsStringAsync().Result;
dynamic JSONdata = JObject.Parse(JSONres);
if (JSONdata.success != "true")
{
return false;
}
return true;
}
}
}