public ActionResult DoLogin(UserDetails u)
        {
            if (ModelState.IsValid)
            {

                EmployeeBusinessLayer bal = new EmployeeBusinessLayer();
                //New Code Start
                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");
                //New Code End
            }
            else
            {
                return View("Login");
            }
        }
Esempio n. 2
0
 public UserStatus GetUserValidity(UserDetails u)
 {
     if (u.UserName == "Admin" && u.Password == "Admin")
     {
         return UserStatus.AuthenticatedAdmin;
     }
     else if (u.UserName == "Tim" && u.Password == "Tim")
     {
         return UserStatus.AuthenticatedUser;
     }
     else
     {
         return UserStatus.NonAuthenticatedUser;
     }
 }