This commit is contained in:
@@ -100,7 +100,7 @@
|
|||||||
<label class="col-md-4 control-label" for="Send"></label>
|
<label class="col-md-4 control-label" for="Send"></label>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="g-recaptcha" data-callback="imNotARobot" data-sitekey="6LcH7GUUAAAAAJIDf_JDZolSv__xN6oqr9Dx79zs"></div>
|
<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>
|
</div>
|
||||||
<!-- <div class="row">
|
<!-- <div class="row">
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ namespace contact.Pages
|
|||||||
_configuration.GetSection("GoogleReCaptcha:secret").Value
|
_configuration.GetSection("GoogleReCaptcha:secret").Value
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
//ModelState.AddModelError(string.Empty, "You failed the CAPTCHA, stupid robot. Go play some 1x1 on SFs instead.");
|
//Return a fail code that will hopefully take us off the spammers list
|
||||||
return StatusCode(400);
|
return StatusCode(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,8 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-md-4 control-label" for="Send"></label>
|
<label class="col-md-4 control-label" for="Send"></label>
|
||||||
<div class="col-md-4">
|
<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>
|
</div>
|
||||||
<!-- <div class="row">
|
<!-- <div class="row">
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Net;
|
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
|
namespace contact.Pages
|
||||||
{
|
{
|
||||||
@@ -17,7 +22,7 @@ namespace contact.Pages
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Company { get; set; }
|
public string Company { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Referrer { get; set; }
|
public string Referrer { get; set; }
|
||||||
[Required, EmailAddress]
|
[Required, EmailAddress]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
@@ -30,7 +35,11 @@ namespace contact.Pages
|
|||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
[BindProperty]
|
[BindProperty]
|
||||||
public RequestFormModel Contact { get; set; }
|
public RequestFormModel Contact { get; set; }
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
public RequestModel(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult OnPost()
|
public ActionResult OnPost()
|
||||||
{
|
{
|
||||||
@@ -38,12 +47,16 @@ namespace contact.Pages
|
|||||||
{
|
{
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
//fuck those Russian spammers
|
if (!ReCaptchaPassed(
|
||||||
if(Contact.Company.ToLowerInvariant()!="google")
|
Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
|
||||||
SendMail();
|
_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
|
SendMail();
|
||||||
//return Redirect("/confirm.html");//sample quickie page I made up
|
|
||||||
return Redirect("https://ayanova.com/confirmed.htm");
|
return Redirect("https://ayanova.com/confirmed.htm");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,5 +113,27 @@ namespace contact.Pages
|
|||||||
{
|
{
|
||||||
Message = "Your contact page.";
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,8 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-md-4 control-label" for="Send"></label>
|
<label class="col-md-4 control-label" for="Send"></label>
|
||||||
<div class="col-md-4">
|
<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>
|
</div>
|
||||||
<!-- <div class="row">
|
<!-- <div class="row">
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Net;
|
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
|
namespace contact.Pages
|
||||||
{
|
{
|
||||||
@@ -17,7 +22,7 @@ namespace contact.Pages
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Company { get; set; }
|
public string Company { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Referrer { get; set; }
|
public string Referrer { get; set; }
|
||||||
[Required, EmailAddress]
|
[Required, EmailAddress]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
@@ -30,7 +35,11 @@ namespace contact.Pages
|
|||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
[BindProperty]
|
[BindProperty]
|
||||||
public RequestFormModel Contact { get; set; }
|
public RequestFormModel Contact { get; set; }
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
public RequestLiteModel(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult OnPost()
|
public ActionResult OnPost()
|
||||||
{
|
{
|
||||||
@@ -38,12 +47,17 @@ namespace contact.Pages
|
|||||||
{
|
{
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
//fuck those Russian spammers
|
if (!ReCaptchaPassed(
|
||||||
if(Contact.Company.ToLowerInvariant()!="google")
|
Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
|
||||||
SendMail();
|
_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");
|
return Redirect("https://ayanova.com/confirmed.htm");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,5 +114,27 @@ namespace contact.Pages
|
|||||||
{
|
{
|
||||||
Message = "Your contact page.";
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user