public JsonResult LoginPost(string YHM, string MM, string YZM) { if (String.IsNullOrEmpty(YHM)) { return(Json(new { flag = false, msg = "请输入用户名" })); } if (String.IsNullOrEmpty(MM)) { return(Json(new { flag = false, msg = "请输入密码" })); } if (String.IsNullOrEmpty(YZM)) { return(Json(new { flag = false, msg = "请输入验证码" })); } if (Session["ImgCode"] == null) { return(Json(new { flag = false, msg = "验证码错误" })); } if (!YZM.ToUpper().Equals(Session["ImgCode"].ToString().ToUpper())) { return(Json(new { flag = false, msg = "验证码错误" })); } try { string mm = md5.to32MD5(MM); object IP_Visit = Session["IP_Visit"]; //来访IP string IP_Submit = GetClientIPv4Address(); //提交IP object IP_Num = Session["IP_Num"]; //来访ip访问次数 Log.WriteLog("来访IP:" + IP_Visit); if (IP_Visit == null && IP_Num == null) { Session["IP_Num"] = "1"; Session["IP_Visit"] = IP_Submit; } else if (IP_Visit.ToString() == IP_Submit && IP_Num.ToString() == "1") { Session["IP_Num"] = "2"; Session["IP_Visit"] = IP_Submit; } else if (IP_Visit.ToString() == IP_Submit && IP_Num.ToString() == "2") { Session["IP_Num"] = "3"; Session["IP_Visit"] = IP_Submit; } else if (IP_Visit.ToString() == IP_Submit && int.Parse((IP_Num == null ? 0 : IP_Num).ToString()) >= 300) { Log.WriteLog("登录失败,来访IP:" + IP_Submit); return(Json(new { flag = false, msg = "你的IP访问次数过多,请换台电脑登录" }, JsonRequestBehavior.AllowGet)); } FormsAuthentication.SetAuthCookie(YHM, false); XtZhbModel yy = new XtzhbService().Login(YHM, mm, 1); if (yy != null) { GLYadmin.GLYLoginIn(yy.zh, yy.yybh, yy.lxr, yy.jsid, yy.id); FormsAuthentication.SetAuthCookie(yy.id.ToString(), false); Log.WriteLog(YHM + ":登录成功!时间:" + System.DateTime.Now); return(Json(new { flag = true, msg = "登陆成功" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { flag = false, msg = "用户名或者密码错误!" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Log.WriteLog(YHM + ":登录失败!:" + ex.Message); return(Json(new { flag = false, msg = "登陆失败" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult LogOut() { GLYadmin.GLYLoginOut(); return(RedirectToAction("Index", "Login")); }