public ActionResult LogOn(LogOnModel model) { if (ModelState.IsValid) { var verifyStatus = UserAuthenticationService.ValidateUser(model.UserName, model.Password); if (verifyStatus == ValidateUserStatus.Success) { FormsService.SignIn(model.UserName, model.RememberMe); if (!String.IsNullOrEmpty(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError(string.Empty, AccountValidation.ValidateUserErrorCodeToString(verifyStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult LogOn(LogOnModel model) { if (ModelState.IsValid) { var verifyStatus = UserAuthenticationService.ValidateUser(model.UserName, model.Password); if (verifyStatus == ValidateUserStatus.Success) { FormsService.SignIn(model.UserName, model.RememberMe); if (!String.IsNullOrEmpty(model.ReturnUrl)) { return Redirect(model.ReturnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError(string.Empty, AccountValidation.ValidateUserErrorCodeToString(verifyStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
public void Log_on_post_returns_view_if_model_state_is_invalid() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; controller.ModelState.AddModelError("", "Dummy error message."); // Act ActionResult result = controller.LogOn(model); // Assert var logonModel = result.AssertViewRendered().WithViewData<LogOnModel>(); Assert.AreEqual(model, logonModel); }
public void Log_on_post_returns_view_if_validate_user_fails() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model); // Assert var logonModel = result.AssertViewRendered().WithViewData<LogOnModel>(); Assert.AreEqual(model, logonModel); Assert.AreNotEqual(string.Empty, controller.ModelState[""].Errors[0].ErrorMessage); }
public void Log_on_post_returns_redirect_on_success_with_return_url() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", ReturnUrl = "/someUrl", RememberMe = false }; // Act ActionResult result = controller.LogOn(model); // Assert result.AssertHttpRedirect().ToUrl("/someUrl"); Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled); }