Пример #1
0
        public ActionResult ResendActivation(ResendActivationViewModel model)
        {
            // Recaptcha challenge
            if (!ReCaptchaPassed(Request))
            {
                ModelState.AddModelError("", "Failed to pass reCaptcha challenge.");
                return(View(model));
            }

            if (!string.IsNullOrEmpty(model.Email))
            {
                var user = ApplicationUserEngine.GetApplicationUser(model.Email);
                if (user != null)
                {
                    if (!string.IsNullOrEmpty(user.ActivationKey))
                    {
                        ApplicationUserEngine.ResendActivationEmail(user.Email);
                        return(View("ResendActivationSuccess", model: model.Email));
                    }

                    ModelState.AddModelError("", "This account has already been activated.");
                }
                else
                {
                    ModelState.AddModelError("", "This email address is not registered for an account.");
                }
            }
            else
            {
                ModelState.AddModelError("", "Invalid email address.");
            }

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> ResendActivation(ResendActivationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ResendActivationConfirmation"));
                }

                // Send an email with this link
                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);

                var welcomeModel = new NameLinkViewModel()
                {
                    Name    = user.UserName,
                    Link    = callbackUrl,
                    BaseURL = Url.Action("Index", "Home", null, protocol: HttpContext.Request.Scheme),
                };
                var messgaeBody = base.RenderViewAsString(welcomeModel, "EmailTemplates/Welcome");
                await _emailSender.SendEmailAsync(model.Email, "Confirm your account", messgaeBody);

                return(View("ResendActivationConfirmation"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }