This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user