public ActionResult Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { DbResultType _result = _userProvider.Authentification(model.UserName, model.Password); if (_result == DbResultType.Executed) { authCookie.AuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return Redirect(Url.Action("List", "Client")); } } else { ModelState.AddModelError("", _result.ToString()); return View(); } } else { return View(); } }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { if (authProvider.AuthUser(model.UserName, model.Password)) { authCookie.AuthCookie(model.UserName, model.RememberMe); <<<<<<< HEAD ======= >>>>>>> 02845c5c33b5b6672c0cde399ce368e726430001 return Redirect(Url.Action("List", "Client")); } else { ModelState.AddModelError("", "Incorrect username or password"); return View(); } } else { return View(); } }
public void Cannot_Login_With_Invalid_Credentials() { // Arrange - create a mock authentication provider Mock<IAuthCookie> mock = new Mock<IAuthCookie>(); mock.Setup(m => m.ValidateUser("badUser", "badPass")).Returns(false); // Arrange - create the view model LoginViewModel model = new LoginViewModel { UserName = "******", Password = "******" }; // Arrange - create the controller AccountController target = new AccountController(mock.Object); // Act - authenticate using valid credentials ActionResult result = target.Login(model, "/MyURL"); // Assert Assert.IsInstanceOfType(typeof(ViewResult), result); Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid); }
public void Can_Login_With_Valid_Credentials() { // Arrange - create a mock authentication provider Mock<IAuthCookie> mock = new Mock<IAuthCookie>(); mock.Setup(m => m.ValidateUser("admin", "secret")).Returns(true); // Arrange - create the view model LoginViewModel model = new LoginViewModel { UserName = "******", Password = "******" }; // Arrange - create the controller AccountController target = new AccountController(mock.Object); // Act - authenticate using valid credentials ActionResult result = target.Login(model, "/MyURL"); // Assert Assert.IsInstanceOfType(typeof(RedirectResult), result); Assert.AreEqual("/MyURL", ((RedirectResult)result).Url); }