Beispiel #1
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

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

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link

                var    eService = new BugTracker.Models.EmailService();
                string code     = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                var userId      = UserManager.FindByNameAsync(model.Email);
                var userEmail   = UserManager.GetEmail(user.Id);
                if (userEmail != null)
                {
                    eService.Send(userEmail,
                                  "Reset Password",
                                  "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
                }

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

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