public async Task <IActionResult> Contact(ContactViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name) ||
                string.IsNullOrWhiteSpace(model.Email) ||
                string.IsNullOrWhiteSpace(model.Subject) ||
                string.IsNullOrWhiteSpace(model.Message)
                )
            {
                model.FailureMessage = "Please complete all fields.";

                return(View(model));
            }

            if (string.IsNullOrWhiteSpace(model.RecaptchaResponse))
            {
                model.FailureMessage = "Something went wrong, please try again.";

                return(View(model));
            }

            if (!RecaptchaHelper.IsReCaptchValid(model.RecaptchaResponse))
            {
                model.FailureMessage = "Something went wrong, please try again.";

                return(View(model));
            }

            var messageText = string.Format("Message from {0}{1}{2}", model.Email, System.Environment.NewLine, model.Message);
            await _emailSender.SendEmailAsync(MasterStrings.AdminEmail, model.Subject, messageText);

            var redirectUrl = string.Format("/Home/Contact?successMessage=Your message '{0}' has been sent.", model.Subject);

            return(ControllerHelper.RedirectToLocal(this, redirectUrl));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(Input.RecaptchaResponse))
                {
                    Input.FailureMessage = "Something went wrong, please try again.";
                    Input.Titles         = CustomerTitle.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList());
                    return(Page());
                }

                if (!RecaptchaHelper.IsReCaptchValid(Input.RecaptchaResponse))
                {
                    Input.FailureMessage = "Something went wrong, please try again.";
                    Input.Titles         = CustomerTitle.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList());
                    return(Page());
                }

                var user = new ApplicationUser {
                    UserName = Input.Email,
                    Email    = Input.Email,
                    Forename = Input.Forename,
                    Surname  = Input.Surname,
                    Title    = Input.Title
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            Input.FailureMessage = "Something went wrong, please try again.";
            Input.Titles         = CustomerTitle.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList());
            return(Page());
        }