public ActionResult EditPasswordForgot(String confirmationToken)
        {
            var model = new EditPasswordForgotViewModel();

            model.ConfirmationToken = confirmationToken;

            return(View(model));
        }
        public async Task <ActionResult> EditPasswordForgot(EditPasswordForgotViewModel model)
        {
            if (ModelState.IsValid)
            {
                User forgottenUser = await _userService.GetByUsernameAsync(model.Username);

                if (forgottenUser != null)
                {
                    //If the password verification token has not expired
                    if (forgottenUser.PasswordVerificationTokenExpiration > DateTime.Now)
                    {
                        if (model.ConfirmationToken == forgottenUser.PasswordVerificationToken)
                        {
                            ServiceOperationResult setPasswordResult =
                                _userService.SetPassword(forgottenUser, model.NewPassword);

                            if (setPasswordResult.Succeeded)
                            {
                                _uow.Commit();

                                await _userService.SendEmailAsync(forgottenUser, EmailHelpers.UserEmails.AccountPropertyChanged("Password"));

                                TempData.Add(KeyTempDataAccountUpdates, new List <String>()
                                {
                                    "Account password has been changed."
                                });

                                return(RedirectToAction("AnonymousAccountUpdates"));
                            }
                            else
                            {
                                ModelState.MergeErrors(setPasswordResult.Errors);
                            }

                            return(View(model));
                        }
                    }

                    return(RedirectToAction("ForgotPassword", new { passwordVerificationTokenExpired = true }));
                }

                ModelState.AddErrorForProperty <EditPasswordForgotViewModel>(m => m.Username, "Invalid username.");
            }

            return(View(model));
        }
        public async Task <ActionResult> EditPasswordForgot(EditPasswordForgotViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userService.GetByEmailWithMembership(model.Email);

                if (user != null)
                {
                    //If the password verification token has expired
                    if (user.Membership.PasswordVerificationTokenExpiration > DateTime.Now)
                    {
                        if (model.ConfirmationToken == user.Membership.PasswordVerificationToken)//user.ConfirmationToken)
                        {
                            _userService.SetPassword(user.UserID, model.NewPassword);

                            _uow.Save();

                            String subject = "Account Password Changed";

                            String body = "This email is to inform you that the password associated with your account has been changed.";

                            await _userService.SendEmailAsync(user.UserID, subject, body);

                            ModelState.Clear();

                            ViewBag.SuccessMessage = "Your password has been changed.";

                            return(View());
                        }
                    }

                    return(RedirectToAction("ForgotPassword", new { passwordVerificationTokenExpired = true }));
                }

                ModelState.AddModelError("Email", "Invalid email address.");
            }

            return(View(model));
        }