public ActionResult Logon(FormCollection cols) { string UserName = cols["UserName"]; ViewData["UserName"] = UserName; string ValidateCode = cols["ValidateCode"]; if (Session["vcode"] == null) { this.ModelState.AddModelError("ValidateCode Timeout", "验证码过期,请重新刷新。"); return(View(cols)); } if (Session["vcode"].ToString() != ValidateCode) { this.ModelState.AddModelError("ValidateCode Error", "验证码不正确。"); return(View()); } Session.Remove("vcode"); Zippy.Data.IDalProvider db = Zippy.Data.DalFactory.CreateProvider(); string Flag = cols["Flag"]; ViewData["Flag"] = Flag; string Password = cols["Password"]; string RememberMe = cols["RememberMe"]; int cookieMinutes = 30; if (RememberMe.IsNotNullOrEmpty() && RememberMe.StartsWith("true")) { cookieMinutes = 60 * 3; } Tenant tenant = null; User user = null; tenant = TenantHelper.Get(Flag, db); if (tenant == null) { this.ModelState.AddModelError("Tenant not found", "租户未找到"); return(View()); } user = UserHelper.Get(UserName, tenant.TenantID.Value, db); if (user == null) { this.ModelState.AddModelError("User not found", "用户未找到"); return(View()); } if (Password.Md6() != user.Password) { this.ModelState.AddModelError("Password not right", "密码不正确"); return(View()); } if (ModelState.IsValid) { Session["tenant"] = tenant; Session["user"] = user; tenant.TenantID.ToString().Save2Cookie("TenantID", DateTime.Now.AddMinutes(cookieMinutes)); user.UserName.Save2Cookie("UserName", DateTime.Now.AddMinutes(cookieMinutes)); return(Return()); } else { return(View()); } }