GeneratePasswordResetToken() public method

public GeneratePasswordResetToken ( string usernameOrEmail, int tokenExpirationMinutes ) : User
usernameOrEmail string
tokenExpirationMinutes int
return User
Ejemplo n.º 1
0
        public virtual ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            // We don't want Login to have us as a return URL
            // By having this value present in the dictionary BUT null, we don't put "returnUrl" on the Login link at all
            ViewData[Constants.ReturnUrlViewDataKey] = null;

            if (ModelState.IsValid)
            {
                var user = UserService.GeneratePasswordResetToken(model.Email, Constants.DefaultPasswordResetTokenExpirationHours * 60);
                if (user != null)
                {
                    var resetPasswordUrl = Url.ConfirmationUrl(
                        MVC.Users.ResetPassword(), user.Username, user.PasswordResetToken, protocol: Request.Url.Scheme);
                    MessageService.SendPasswordResetInstructions(user, resetPasswordUrl);

                    TempData["Email"] = user.EmailAddress;
                    return(RedirectToAction(MVC.Users.PasswordSent()));
                }

                ModelState.AddModelError("Email", "Could not find anyone with that email.");
            }

            return(View(model));
        }