public ActionResult DoLogin(UserDetails u) { if (!ModelState.IsValid) return View("Login"); var bal = new EmployeeBusinessLayer(); //New Code Start var status = bal.GetUserValidity(u); if (status == UserStatus.AuthenticatedAdmin || status == UserStatus.AuthentucatedUser) { var isAdmin = status == UserStatus.AuthenticatedAdmin; FormsAuthentication.SetAuthCookie(u.UserName, false); Session["IsAdmin"] = isAdmin; return RedirectToAction("Index", "Employee"); } ModelState.AddModelError("CredentialError", "Invalid Username or Password"); return View("Login"); }
public ActionResult DoLogin(UserDetails u) { if (ModelState.IsValid) { EmployeeBusinessLayer bal = new EmployeeBusinessLayer(); #region //if (bal.IsValidUser(u)) //{ // FormsAuthentication.SetAuthCookie(u.UserName, false); // return RedirectToAction("Index", "Employee"); //} //else //{ // ModelState.AddModelError("CredentialError", "InValid Username or Password"); // return View("Login"); //} #endregion UserStatus status = bal.GetUserValidity(u); bool IsAdmin = false; if (status==UserStatus.AuthenticatedAdmin) { IsAdmin = true; } else if (status==UserStatus.AuthenticatedUser) { IsAdmin = false; } else { ModelState.AddModelError("CredentialError", "Invalid Username or Password"); return View("Login"); } FormsAuthentication.SetAuthCookie(u.UserName, false); Session["IsAdmin"] = IsAdmin; return RedirectToAction("Index", "Employee"); } else { return View("Login"); } }