public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var query = new SearchQuery<UserModel>(); // query.AddFilter(product => product.UserName ==""); //this is the same as the following query.AddFilter(c => c.UserName == model.UserName); query.Take = 1; var result = unitOfWork.UserRepository.Search(query).Entities.FirstOrDefault(); if (result != null) { if (result.Password == model.Password) { FormsAuthentication.SetAuthCookie(model.UserName, false); return RedirectToAction("Index", "Location"); } ModelState.AddModelError("", "Login data is incorrect!"); return View(model); } ModelState.AddModelError("", "Login data is incorrect!"); return View(model); } return View(); }
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); }