Example #1
0
        public ActionResult Index(User userLog)
        {
            var user = db.UserList.SingleOrDefault(u => u.UserName.Equals(userLog.UserName));

            if (user == null)
            {
                ModelState.AddModelError("", "User not found!");
            }
            else
            {
                Session["uname"] = user.UserName;
                if (userLog.Passcode.Equals(PasscodeSecurity.decPasscode(user.Passcode)))
                {
                    if (user.Roles == "Admin")
                    {
                        return(RedirectToAction("Create", "Computers"));
                    }
                    else if (user.Roles == "User")
                    {
                        return(RedirectToAction("Index", "Computers"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid passcode!");
                }
            }
            return(View());
        }
        public ActionResult Login(User logUser)
        {
            var user = db.UserList.Find(logUser.Username);

            if (user == null)
            {
                ModelState.AddModelError("", @Lab07.Languages.Lg.UserNotFound);
            }
            else
            {
                if (logUser.Passcode.Equals(PasscodeSecurity.decPasscode(user.Passcode)))
                {
                    Session["User"] = user;
                    if (user.IsAdmin == true)
                    {
                        return(RedirectToAction("IndexAdmin", "Home"));
                    }
                    else if (user.IsAdmin == false)
                    {
                        return(RedirectToAction("IndexUser", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", @Lab07.Languages.Lg.WrongPassword);
                }
            }
            return(View());
        }