Exemplo n.º 1
0
        public ActionResult Check(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", model));
            }

            LogService.AdminLogin(model.UserName + ";" + Request.UserHostAddress + ";" + Request.UserAgent);

            var identity = UserService.CheckIdentity(model.UserName, model.Password, true);

            if (identity != null)
            {
                //AuthenticationManager.SignOut();
                AuthenticationManager.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = model.RememberMe == "on"
                }, identity);
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ModelState.AddModelError("", "无效的登录尝试。");
                return(View("Index", model));
            }
        }