public ActionResult Index(VmAdminLogin model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (model.Password == Properties.Settings.Default.AdminPassword)
     {
         //授权
         AspFormsAuthentication.SetAuthenticationToken("Admin", new[] { "Admin" }, true);
         //跳到AdminHome
         return(RedirectToAction("AdminHome"));
     }
     ModelState.AddModelError("", "密码错误!");
     return(View(model));
 }
예제 #2
0
        public ActionResult Login(VmLogin model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //查数据库,用户是否正确
            var userNow = _accountService.CheckLogin(model);

            if (userNow == null)
            {
                ModelState.AddModelError("", "用户名或密码错误");
                return(PartialView(model));
            }
            Session.Add("userNow", userNow);
            //授权
            AspFormsAuthentication.SetAuthenticationToken(userNow.UserName, new[] { "Logon" }, true);
            return(RedirectToAction("Index", "Home"));
        }