예제 #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());
        }
 public ActionResult Create(User newUser)
 {
     if (ModelState.IsValid)
     {
         newUser.Passcode = PasscodeSecurity.encPasscode(newUser.Passcode);
         db.UserList.Add(newUser);
         db.SaveChanges();
         ModelState.AddModelError("", @Lab07.Languages.Lg.AddUserSuccess);
     }
     return(View());
 }
 public ActionResult Create(User newUser)
 {
     if (ModelState.IsValid)
     {
         newUser.Passcode        = PasscodeSecurity.encPasscode(newUser.Passcode);
         db.Entry(newUser).State = EntityState.Added;
         db.SaveChanges();
         ModelState.AddModelError("", "Add user completed!");
         TempData["Msg"] = "Add user completed!";
     }
     return(View());
 }