private async Task ValidateCaptchaAsync(SendResetPasswordLinkCommand command)
 {
     if (!await _captchaService
         .ValidateAsync(command.CaptchaId, command.CaptchaCode))
     {
         throw new ValidationException(ErrorCodes.InvalidCaptcha);
     }
 }
Beispiel #2
0
 private async Task ValidateCaptchaAsync(CreateUserCommand command)
 {
     if (!await _captchaService
         .ValidateAsync(command.CaptchaId, command.CaptchaCode))
     {
         throw new ValidationException(ErrorCodes.InvalidCaptcha);
     }
 }
        public async Task <ActionResult> SendMessage(ContactEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = "Please correctly fill all the required fields." }));
            }

            if (!string.IsNullOrWhiteSpace(SiteSettings.ReCaptchaKey) && !string.IsNullOrWhiteSpace(SiteSettings.ReCaptchaSecret))
            {
                var captchaResponse = await _captchaService.ValidateAsync(SiteSettings.ReCaptchaSecret, Request.Form["g-recaptcha-response"]);

                if (!captchaResponse.Success)
                {
                    return(Json(new { success = false, message = string.Format("Captcha validation failed. ({0})", captchaResponse.ErrorCodes[0]) }));
                }
            }

            var from        = new MailAddress(model.Email, model.Name);
            var mailMessage = new MailMessage()
            {
                From    = from,
                To      = { SiteSettings.ContactEmail },
                Subject = model.Subject,
                Body    = model.Message
            };

            try
            {
                await _emailService.SendAsync(mailMessage, SiteSettings.SMTPHost, SiteSettings.SMTPPort, SiteSettings.SMTPUserName, SiteSettings.SMTPPassword, SiteSettings.SMTPEnableSSL);

                return(Json(new { success = true, message = "Your message has been successfully sent." }));
            }
            catch
            {
                return(Json(new { success = false, message = "An error occurred while sending your mail." }));
            }
            finally
            {
                mailMessage.Dispose();
            }
        }