Пример #1
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    ModelState.AddModelError("", AccountResources.EmailDoesntExistOrNotConfirmed);
                    return(View());
                }

                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

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

                IUserMailer userMailer = new UserMailer();
                var         email      = userMailer.SendPasswordReset(model.Email.Trim(), code, user.Id);
                email.SendAsync();

                var messageModel = new MessageViewModel()
                {
                    Body   = AccountResources.PasswordRecoveryEmailSent,
                    Header = AccountResources.PasswordRecovery
                };

                return(RedirectToAction("Message", "Home", messageModel));
            }

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