private async Task ValidateCaptchaAsync(SendResetPasswordLinkCommand command)
 {
     if (!await _captchaService
         .ValidateAsync(command.CaptchaId, command.CaptchaCode))
     {
         throw new ValidationException(ErrorCodes.InvalidCaptcha);
     }
 }
Exemplo n.º 2
0
 private async Task ValidateCaptchaAsync(CreateUserCommand command)
 {
     if (!await _captchaService
         .ValidateAsync(command.CaptchaId, command.CaptchaCode))
     {
         throw new ValidationException(ErrorCodes.InvalidCaptcha);
     }
 }
Exemplo n.º 3
0
        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();
            }
        }