This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -20,7 +20,7 @@
|
||||
"args": "${auto-detect-url}",
|
||||
"windows": {
|
||||
"command": "cmd.exe",
|
||||
"args": "/C start ${auto-detect-url}"
|
||||
"args": "/C start http://localhost:3002/contact"
|
||||
},
|
||||
"osx": {
|
||||
"command": "open"
|
||||
|
||||
@@ -92,11 +92,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Button -->
|
||||
<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" >Send us your question</button>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="row">
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -29,6 +34,11 @@ namespace contact.Pages
|
||||
[BindProperty]
|
||||
public ContactFormModel Contact { get; set; }
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
public ContactModel(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public ActionResult OnPost()
|
||||
{
|
||||
@@ -36,8 +46,21 @@ namespace contact.Pages
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
|
||||
|
||||
if (!ReCaptchaPassed(
|
||||
Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
|
||||
_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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//fuck those Russian spammers
|
||||
if(Contact.Company.ToLowerInvariant()!="google")
|
||||
if (Contact.Company.ToLowerInvariant() != "google")
|
||||
SendMail();
|
||||
|
||||
//TODO: go to a successful submit page on the ayanova site
|
||||
@@ -67,7 +90,7 @@ namespace contact.Pages
|
||||
// smtpClient.EnableSsl=true;
|
||||
// smtpClient.Port=465;
|
||||
// smtpClient.DeliveryMethod= SmtpDeliveryMethod.Network;
|
||||
|
||||
|
||||
|
||||
|
||||
//NOTE: Do not use the noreply email address to send mail, it crashes the server somehow
|
||||
@@ -75,12 +98,12 @@ namespace contact.Pages
|
||||
//******************************************************************************************************************
|
||||
//******************************************************************************************************************
|
||||
//TEST CRASH
|
||||
// smtpClient.Credentials = new System.Net.NetworkCredential("noreply@ayanova.com", "91768700489f8edd28aa71e3e0f4073eba54ce83c4c1a6a910700fa94094ddfd");
|
||||
|
||||
// smtpClient.Credentials = new System.Net.NetworkCredential("noreply@ayanova.com", "91768700489f8edd28aa71e3e0f4073eba54ce83c4c1a6a910700fa94094ddfd");
|
||||
|
||||
smtpClient.Credentials = new System.Net.NetworkCredential("webmaster@ayanova.com", "c63c17add818fca81cae71a241ea1b552675a86280b7e7e45d36cbf2e8f3bc0e");
|
||||
//******************************************************************************************************************
|
||||
//******************************************************************************************************************
|
||||
|
||||
|
||||
smtpClient.Send(message);
|
||||
}
|
||||
}
|
||||
@@ -111,5 +134,29 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
|
||||
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
|
||||
</environment>
|
||||
|
||||
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<!-- <nav class="navbar navbar-inverse navbar-fixed-top">
|
||||
@@ -68,7 +72,13 @@
|
||||
</script>
|
||||
<script src="~/js/site.min.js" asp-append-version="true"></script>
|
||||
</environment>
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#btnsubmit").hide();
|
||||
var imNotARobot = function() {
|
||||
//console.info("Button was clicked");
|
||||
$("#btnsubmit").show();
|
||||
};
|
||||
</script>
|
||||
@RenderSection("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -4,5 +4,9 @@
|
||||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"GoogleReCaptcha": {
|
||||
"key": "6LcH7GUUAAAAAJIDf_JDZolSv__xN6oqr9Dx79zs",
|
||||
"secret": "6LcH7GUUAAAAAERHuA3fWDcMIlJ3QHE_WNZm4BSO"
|
||||
}
|
||||
}
|
||||
|
||||
14
notes
14
notes
@@ -1,10 +1,14 @@
|
||||
Todo:
|
||||
Put up to server for testing from test static site copy before getting too crazy with it
|
||||
Once it confirms to work then:
|
||||
todo: captcha
|
||||
https://developers.google.com/recaptcha/intro
|
||||
|
||||
Proper redirect after successful submit
|
||||
|
||||
Add request forms
|
||||
|
||||
|
||||
|
||||
CAPTCHA 2
|
||||
https://retifrav.github.io/blog/2017/08/23/dotnet-core-mvc-recaptcha/
|
||||
Secret key: 6LcH7GUUAAAAAERHuA3fWDcMIlJ3QHE_WNZm4BSO
|
||||
Site key: 6LcH7GUUAAAAAJIDf_JDZolSv__xN6oqr9Dx79zs
|
||||
|
||||
|
||||
$Profit
|
||||
|
||||
Reference in New Issue
Block a user