public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } // 如果我们进行到这一步时某个地方出错,则重新显示表单 ModelState.AddModelError("", "提供的用户名或密码不正确。"); return View(model); }
public ActionResult Login(LoginModel model, string returnUrl) { var myAuthenticator = new Web.Models.Authenticate(); if (ModelState.IsValid && myAuthenticator.IsAuthenticated(model.UserName,model.Password)) { Session["User"] = model.UserName.Split('@')[0]; return RedirectToLocal(returnUrl); } ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }
public ActionResult Login(LoginModel model, string returnUrl) { if(ModelState.IsValid) { if (_auth.Authenticate(model.Email, model.Password)) { return returnUrl == null ? _redirect.ToDashboard(model.Email) : _redirect.ToUrl(returnUrl); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } return View("Index", model); }
public void Login_Post_Success_With_ReturnUrl() { // arrange var service = new Mock<IAuthenticationService>(); var redirect = new RedirectService(); var controller = new LoginController(service.Object, redirect); var model = new LoginModel() { Email = "*****@*****.**", Password = "******" }; service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(true); //act var result = controller.Login(model, "somewhere") as RedirectResult; //assert Assert.That(result.Url, Is.EqualTo("somewhere")); }
public void Login_Post_Success() { // arrange var service = new Mock<IAuthenticationService>(); var redirect = new RedirectService(); var controller = new LoginController(service.Object, redirect); var model = new LoginModel() { Email = "*****@*****.**", Password = "******" }; service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(true); //act var result = controller.Login(model, null) as RedirectResult; //assert result.Url.Should().Be("~/user/[email protected]"); }
public JsonResult JsonLogin(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); return Json(new {success = true, redirect = returnUrl}); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed return Json(new {errors = GetErrorsFromModelState()}); }
public ActionResult Login(LoginModel model, string returnUrl) { try { Boolean authenticated = false; authenticated = Auth.Authenticate(model.UserName, model.Password, null, true); if (authenticated) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); return RedirectToAction("Index", "Home"); } } catch (Exception exception) { ViewBag.HasError = true; ModelState.AddModelError("", exception.Message); } return View(model); }
public ActionResult Index(LoginModel loginModel) { if (!ModelState.IsValid) { return View(loginModel); } if (!authenticator.Authenticate(loginModel.EmailAddress, loginModel.Password)) { return View(loginModel); } return Json(true); }
public void Login_Post_Fail() { // arrange var service = new Mock<IAuthenticationService>(); var redirect = new RedirectService(); var controller = new LoginController(service.Object, redirect); var model = new LoginModel() { Email = "*****@*****.**", Password = "******" }; service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(false); //act var result = controller.Login(model, "somewhere") as ViewResult; //assert Assert.That(controller.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("The user name or password provided is incorrect.")); }