public ActionResult Login(LoginViewModel model) { //if (ModelState.IsValid) //{ if (string.IsNullOrEmpty(model.Account)) { model.ErrorMsg[0] = "请输入账号"; } if (string.IsNullOrEmpty(model.Password)) { model.ErrorMsg[1] = "请输入密码"; } if (model.ErrorMsg.Count(_ => !string.IsNullOrEmpty(_)) > 0) { return(View(model)); } var loginUser = usrOp.GetSingleData(_ => _.Account == model.Account && _.Password == MD5Helper.MD5Encrypt16(model.Password)); if (loginUser == null) { ModelState.AddModelError("LoginPwd", "账号或密码不正确,请重新输入!"); model.ErrorMsg[2] = "账号或密码不正确,请重新输入!"; return(View(model)); } // 当前登录用户信息存入Session Session.Add("CurrenyUser", loginUser); // 设置ticket票据的名称为用户的id,设置有效时间为60分钟 FormsAuthHelp.AddFormsAuthCookie(loginUser.Account, loginUser, 1); //} return(Redirect("~/Home/Main")); }
public ActionResult Logout() { Session.RemoveAll(); FormsAuthHelp.RemoveFormsAuthCookie(); return(Redirect("~/Home/Login")); }