public ActionResult DoLogin(UserDetails u) { if (ModelState.IsValid) { EmployeeBusinessLayer empBLayer = new EmployeeBusinessLayer(); UserStatus status = empBLayer.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"); } }
public UserStatus GetUserValidity(UserDetails u) { if (u.UserName == "Admin" && u.Password == "Admin") { return UserStatus.AuthenticatedAdmin; } else if (u.UserName == "Asif" && u.Password == "Asif") { return UserStatus.AuthenticatedUser; } else { return UserStatus.NonAuthenticatedUser; } }