public ActionResult ChangePassword(UserInformationView userInformation)
        {
            ViewBag.PageTitle = "Change Password";
            try
            {
                string userName = string.IsNullOrEmpty(userInformation.UserName)
                               ? HttpContext.User.Identity.Name
                               : userInformation.UserName;
                if (_memberShipProvider.ChangePassword(userName, userInformation.Password,
                                                       userInformation.ChangePassword))
                {
                    ViewBag.SuccessMessage = "Your password has been sucessfully changed. Please login with your new password";
                    return View("Login");
                }
                ViewBag.ErrorMessage = "Password could not be changed. Please retry";

            }
            catch (Exception exception)
            {
                if (exception is ArgumentException)
                {
                    ViewBag.ErrorMessage = exception.Message;
                    return View(userInformation);
                }
                ViewBag.ErrorMessage = "An error occurred trying to change your password. Please try again";
                throw;
            }

            return View(userInformation);
        }
        public void Change_Password_Displays_Success_When_Password_Changed()
        {
            var userInformation = new UserInformationView { UserName = "******", Password = "******", ChangePassword = "******", ConfirmPassword = "******" };
            _memberShipMock.Setup(x => x.ChangePassword(userInformation.UserName, userInformation.Password, userInformation.ChangePassword)).Returns(true);
            var accountController = new AccountController(_memberShipMock.Object);
            ActionResult result = accountController.ChangePassword(userInformation);

            Assert.That(result, Is.TypeOf<ViewResult>());
            Assert.That(((ViewResult)result).ViewName,Is.EqualTo("Login"));
        }
 public ActionResult ChangePassword(string resetPassword, string userName)
 {
     ViewBag.PageTitle = "Change Password";
     var model = new UserInformationView();
     if (!string.IsNullOrEmpty(resetPassword)&&!string.IsNullOrEmpty(userName))
     {
         ViewBag.InformationalMessage = "Your password has been reset to a temp. password. Please change it";
         model.Password = resetPassword;
         model.UserName = userName;
     }
     return View(model);
 }
        public void Setup()
        {
            _memberShipMock = new Mock<IMembershipProvider>();

            _userInformationView = new UserInformationView
            {
                UserName = "******",
                Password = "******",
                ConfirmPassword = "******",
                Email = "",
                SecretQuestion = "",
                HintAnswer = "",
                //ReturnUrl = "www.asp.net/mvc"
            };
            BootStrapper.MapDomainAndViewTypes();
        }
        public ActionResult Register(UserInformationView userInformationView)
        {
            try
            {
                var userInformation = Mapper.Map<UserInformationView, UserInformation>(userInformationView);
                MembershipCreateResult membershipCreateResult = _memberShipProvider.CreateUser(userInformation, true);
                if (membershipCreateResult.CreateStatus == MembershipCreateStatus.Success)
                {
                    if (_memberShipProvider.ValidateUser(userInformationView.UserName, userInformationView.Password))
                    {
                        ViewBag.SuccessMessage = "Your account has been successfully created. Please login with your credentials";
                        return View("Login");
                    }
                    ViewBag.ErrorMessage =
                        "Login failed! Please make sure you are using the correct user name and password.";
                }
                else
                    ViewBag.ErrorMessage = GetErrorMessage(membershipCreateResult.CreateStatus);
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = "An exception occurred. Please try again " + e.Message;
                throw;
            }

            ViewBag.PageTitle = "Register New User";
            return View(userInformationView);
        }
 public ActionResult ForgotPassword(string userName, string hintAnswer)
 {
     if (!string.IsNullOrEmpty(hintAnswer))
     {
         string resetPassword = _memberShipProvider.ResetPassword(userName, hintAnswer);
         if (_memberShipProvider.ValidateUser(userName, resetPassword))
             return RedirectToAction("ChangePassword", new { resetPassword,userName });
     }
     var membershipUserWrapper = _memberShipProvider.GetUser(userName, false);
     var userInformation = new UserInformationView();
     if (null != membershipUserWrapper)
     {
         userInformation.SecretQuestion = membershipUserWrapper.SecretQuestion;
         userInformation.UserName = userName;
     }
     else
     {
         ViewBag.ErrorMessage = "The user you have specified is invalid, please recheck your username and try again";
         userInformation.SecretQuestion = string.Empty;
     }
     ViewBag.PageTitle = "Forgot Password";
     return View(userInformation);
 }