Пример #1
0
        public ActionResult ChangeCurrent()
        {
            var user = this._userService.GetApplicationUser(TempData["username"].ToString());

            var changeCurrentPasswordModel = new ChangeCurrentPasswordModel(user.Id);

            return(this.View(changeCurrentPasswordModel));
        }
Пример #2
0
        public ActionResult ChangeCurrent()
        {
            var user = this.userService.GetApplicationUser(TempData["username"].ToString());

            var changeCurrentPasswordModel = new ChangeCurrentPasswordModel(user.Id, user.UserName, user.FirstName, user.LastName);

            ViewBag.LastLoginDate = user.LastLoginDate;

            return(this.View(changeCurrentPasswordModel));
        }
Пример #3
0
        public void WhenISubmitTheChangeCurrentPasswordPage_AndTheModelIsInValid_ItShouldReturnTheRightViewAndContainTheModel()
        {
            _controller.ModelState.AddModelError("Password", "Password has already been used recently");

            var model = new ChangeCurrentPasswordModel();

            var result = (ViewResult)this._controller.ChangeCurrent(model);

            result.Should().NotBeNull();
            result.Model.Should().BeOfType <ChangeCurrentPasswordModel>();
            result.TempData["message"].ToString().ShouldBeEquivalentTo("Please correct the errors and try again.");
        }
Пример #4
0
        public ActionResult ChangeCurrent(ChangeCurrentPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                this._userService.ChangePassword(model.UserId, model.CurrentPassword, model.NewPassword);

                var user = this._userService.GetApplicationUserById(model.UserId);

                this._userService.SignIn(user, false);

                this._userService.UpdateUserLastLogindate(model.UserId);

                return(RedirectToAction("Index", "Dashboard"));
            }
            else
            {
                TempData["message"] = "Please correct the errors and try again.";
                return(View(model));
            }
        }
Пример #5
0
        public ActionResult ChangeCurrent(ChangeCurrentPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                this.userService.ChangePassword(model.UserId, model.CurrentPassword, model.NewPassword);

                var user = this.userService.GetApplicationUserById(model.UserId);

                this.userService.SignIn(user, false);

                this.userService.UpdateUserLastLogindate(model.UserId);

                Logger.Info(string.Format("{0} changed password", HttpContext.User.Identity.Name));

                return(this.RedirectToAction("Index", "Home"));
            }
            else
            {
                this.TempData["message"] = "Please correct the errors and try again.";
                return(this.View(model));
            }
        }
Пример #6
0
        public void WhenISubmitTheChangeCurrentPasswordPage_AndTheModelIsValid_ItShouldReturnTheRightViewAndContainTheModel()
        {
            var model = new ChangeCurrentPasswordModel();

            var user = new ApplicationUser();

            this._userService.Setup(x => x.ChangePassword(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));
            this._userService.Setup(x => x.GetApplicationUserById(It.IsAny <string>())).Returns(user);
            this._userService.Setup(x => x.SignIn(user, false));
            this._userService.Setup(x => x.UpdateUserLastLogindate(It.IsAny <string>()));

            var result = this._controller.ChangeCurrent(model) as RedirectToRouteResult;

            result.Should().NotBeNull();

            result.Should().BeOfType <RedirectToRouteResult>();
            this._userService.Verify(x => x.ChangePassword(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce);
            this._userService.Verify(x => x.GetApplicationUserById(It.IsAny <string>()), Times.AtLeastOnce);
            this._userService.Verify(x => x.SignIn(user, false), Times.AtLeastOnce);
            this._userService.Verify(x => x.UpdateUserLastLogindate(It.IsAny <string>()), Times.AtLeastOnce);
            result.RouteValues["controller"].Should().Be("Dashboard");
            result.RouteValues["action"].Should().Be("Index");
        }
Пример #7
0
 public void Setup()
 {
     this.passwordValidAttribute     = new PasswordValidAttribute("UserName", "FirstName", "LastName");
     this.changeCurrentPasswordModel = new ChangeCurrentPasswordModel("userId", "myUserNames", "firstName", "lastname");
 }