Recaptcha for contact and registration page implemented

This commit is contained in:
2022-10-21 14:43:33 -04:00
parent 0160c1d7b5
commit 8fd0796019
10 changed files with 155 additions and 42 deletions
+13 -4
View File
@@ -11,21 +11,30 @@ namespace LeafWeb.WebCms.Controllers
public ActionResult Index()
{
var viewModel = new ContactForm();
return PartialView(viewModel);
// if user is logged in, pre fill the name and email
var member = Members.GetCurrentMember();
if (member != null)
{
viewModel.Name = member.Name;
viewModel.Email= (string)member.GetProperty("Email").Value;
}
return PartialView(viewModel);
}
[HttpPost]
[ValidateRecaptcha]
public ActionResult Submit(ContactForm viewModel)
{
if (ModelState.IsValid) // HttpParamMatch indicates it's backing out from Confirm
if (ModelState.IsValid)
{
BackgroundJob.Enqueue<EmailNotificationService>(
BackgroundJob.Enqueue<EmailNotificationService>(
e => e.SendContactEmail(viewModel));
var logger = LogManager.GetLogger(GetType());
logger.Info($"Contact: Name:{viewModel.Name} Added, Email:{viewModel.Email}, Message:{viewModel.Message}");
SetStatusMessage("Your message has been sent!", StatusType.Success);
SetStatusMessage($"Thank you, {viewModel.Name}. Your message has been sent" , StatusType.Success);
return RedirectToCurrentUmbracoPage();
}