public ActionResult DoLogin(UserDetails u) { if (ModelState.IsValid) { EmployeeBusinessLayer bal = new EmployeeBusinessLayer(); UserStatus status = bal.GetUserValidity(u); bool IsAdmin = false; if (status == UserStatus.AuthenticatedAdmin) { IsAdmin = true; } else if (status == UserStatus.AuthentucatedUser) { 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 bool IsValidUser(UserDetails u) //{ // if (u.UserName == "Admin" && u.Password == "Admin") // { // return true; // } // else // { // return false; // } //} public UserStatus GetUserValidity(UserDetails u) { if (u.UserName == "Admin" && u.Password == "Admin") { return UserStatus.AuthenticatedAdmin; } else if (u.UserName == "Sukesh" && u.Password == "Sukesh") { return UserStatus.AuthentucatedUser; } else { return UserStatus.NonAuthenticatedUser; } }