コード例 #1
0
        public void UpdatePassword_Post_Returns_Redirect_When_Password_Fails()
        {
            ChangePasswordModel model = new ChangePasswordModel
                                            {
                                                OldPassword = "******",
                                                NewPassword = "******",
                                                ConfirmPassword = "******"
                                            };

            ActionResult result = controller.UpdatePassword(model);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
            Assert.IsNotNull(controller.TempData["ChangePasswordModel"]);
        }
コード例 #2
0
        public void UpdatePassword_Post_Returns_Redirect_On_Success()
        {
            ChangePasswordModel model = new ChangePasswordModel
                                            {
                                                OldPassword = "******",
                                                NewPassword = "******",
                                                ConfirmPassword = "******"
                                            };

            ActionResult result = controller.UpdatePassword(model);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
            Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]);
        }
コード例 #3
0
 private ActionResult PasswordChangeFailed(ChangePasswordModel model)
 {
     ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
     TempData["ChangePasswordModel"] = model;
     return RedirectToAction("ChangePassword");
 }
コード例 #4
0
        public void UpdatePassword_Post_Returns_Redirect_If_ModelState_Invalid()
        {
            ChangePasswordModel model = new ChangePasswordModel
                                            {
                                                OldPassword = "******",
                                                NewPassword = "******",
                                                ConfirmPassword = "******"
                                            };

            controller.ModelState.AddModelError("", "Dummy error message.");
            ActionResult result = controller.UpdatePassword(model);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
            Assert.IsNotNull(controller.TempData["ChangePasswordModel"]);
        }
コード例 #5
0
        public ActionResult SavePassword(ChangePasswordModel model, string returnUrl = "")
        {
            if (ModelState.IsValid)
            {
                using (new UnitOfWorkScope())
                {
                    var email = User.Identity.Name;
                    var userProfile = userProfileRepository.FindUserProfileByEmail(email).FirstOrDefault();

                    if (userProfile == null)
                    {
                        return HttpNotFound("The user profile you are looking for could not be found.");
                    }

                    if (!MembershipService.ChangePassword(email, model.OldPassword, model.NewPassword))
                    {
                        return PasswordChangeFailed(model);
                    }

                    var user = userProfile.Users.FirstOrDefault();

                    if (user != null)
                    {
                        user.ForcePasswordChange = false;
                        userProfileRepository.Save();
                    }

                    var mailModel = Mapper.Map<UserProfile, RegisterModel>(userProfile);
                    accountMailer.PasswordChange(mailModel).SendAsync();

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        TempData["UserFeedback"] = "Thank you! Your password has been successfully updated.";
                        return Redirect(returnUrl);
                    }

                    return RedirectToAction("ChangePasswordSuccess");
                }
            }

            return PasswordChangeFailed(model);
        }