コード例 #1
0
        public ActionResult Login(UserDetails ud)
        {
            if (ModelState.IsValid)
            {
                EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
                UserStatus usr = ebl.GetValidUser(ud);
                bool IsAdmin = false;
                if (usr == UserStatus.AuthenticatedAdmin)
                {
                    IsAdmin = true;
                }

                else if (usr == UserStatus.Authenticateduser)
                {
                    IsAdmin = false;
                }
                else
                {
                    ModelState.AddModelError("CredentialError", "Invalid Credentials");
                    return View("Login");
                }
                FormsAuthentication.SetAuthCookie(ud.Username, false);
                Session["Admin"] = IsAdmin;
                return RedirectToAction("Index", "Employee");
            }

            else
                return View("Login");
        }
コード例 #2
0
        //public bool IsValidUser(UserDetails ud)
        //{
        //    if (ud.Username == "Admin" && ud.Password == "Admin")
        //    {
        //        return true;
        //    }
        //    else
        //       return false;
        //}
        public UserStatus GetValidUser(UserDetails ud)
        {
            if (ud.Username == "Admin" && ud.Password == "Admin")
            {
                return UserStatus.AuthenticatedAdmin;
            }
            else if (ud.Username == "Vicky" && ud.Password == "Vicky")
            {
                return UserStatus.Authenticateduser;
            }

            else
                return UserStatus.NonAuthenticateduser;
        }