/// <summary> /// 判断管理员是否已经登录(解决Session超时问题) /// </summary> public bool IsAdminLogin() { //如果Session为Null if (Session[AngelConst.ANGEL_SESSION_ADMIN] != null) { return(true); } else { //检查Cookies string adminname = AngelUtils.GetCookie("AdminName", "AngelRM"); string adminpwd = AngelUtils.GetCookie("AdminPwd", "AngelRM"); if (adminname != "" && adminpwd != "") { Business.Angel_Admin bll = new Business.Angel_Admin(); Model.Angel_Admin model = bll.GetModel(adminname, adminpwd); if (model != null) { Session[AngelConst.ANGEL_SESSION_ADMIN] = model; return(true); } } } return(false); }
protected void btnSubmit_Click(object sender, EventArgs e) { string userName = txtUserName.Text.Trim(); string userPwd = txtPassword.Text.Trim(); if (userName.Equals("") || userPwd.Equals("")) { msgtip.InnerHtml = "请输入用户名或密码"; return; } if (Session["AdminLoginCount"] == null) { Session["AdminLoginCount"] = 1; } else { Session["AdminLoginCount"] = Convert.ToInt32(Session["AdminLoginCount"]) + 1; } //判断登录错误次数 if (Session["AdminLoginCount"] != null && Convert.ToInt32(Session["AdminLoginCount"]) > 5) { msgtip.InnerHtml = "错误超过5次,关闭浏览器重新登录!"; return; } Business.Angel_Admin bll = new Business.Angel_Admin(); Model.Angel_Admin model = bll.GetModel(userName, userPwd); if (model == null) { msgtip.InnerHtml = "用户名或密码有误,请重试!"; return; } Session[AngelConst.ANGEL_SESSION_ADMIN] = model; Session.Timeout = 45; //写入登录日志 Model.Angel_Siteconfig SiteconfigInfo = new Business.Angel_Siteconfig().loadConfig(); if (SiteconfigInfo.Islogstatus > 0) { Model.Angel_Admin_log adminlog = new Model.Angel_Admin_log(); adminlog.AdminId = model.ID; adminlog.AdminName = model.LoginName; adminlog.OperateIP = AngelRequest.GetIP(); adminlog.Operate_Value = AngelActionName.ActionName.Login.ToString(); adminlog.Explain = "用户登录"; adminlog.AddTime = DateTime.Now; Business.Angel_Admin_log blllog = new Business.Angel_Admin_log(); bool aaa = blllog.Add(adminlog); // new Business.Angel_Admin_log().Add(adminlog); } //写入Cookies记住用户名 if (this.Issavepwd.Checked == true) { AngelUtils.WriteCookie("AgeRememberName", model.UserName, 16000); } else { AngelUtils.WriteCookie("AgeRememberName", "", 16000); } AngelUtils.WriteCookie("AgeRememberName", model.UserName, 16000); AngelUtils.WriteCookie("AdminName", "AngelRM", model.UserName); Response.Redirect("MainFrame/Main.aspx"); return; }
public void ProcessRequest(HttpContext context) { AngelRM.Business.Angel_Admin ObjectBLL = new Business.Angel_Admin(); string ActionName = context.Request.Params["action"]; //根据相应的表进行操作 switch (ActionName) { case "SaveDB": Model.Angel_Admin modeobj = new Model.Angel_Admin(); modeobj.RoleId = Convert.ToInt32(context.Request.Params["RoleId"]); modeobj.LoginName = context.Request.Params["LoginName"]; modeobj.Password = AngelDESEncrypt.Encrypt(context.Request.Params["Password"]); modeobj.UserName = context.Request.Params["UserName"]; modeobj.UserEmail = context.Request.Params["UserEmail"]; modeobj.AddTime = DateTime.Now; modeobj.IsWorking = Convert.ToInt32(context.Request.Params["IsWorking"]); if (modeobj.LoginName == "" || modeobj.LoginName == null || modeobj.RoleId == null || modeobj.AddTime == null || modeobj.IsWorking == null) { context.Response.Write("{\"success\":false}"); } if (context.Request.Params["method"] == "add") { bool iscount = ObjectBLL.Add(modeobj); if (iscount) { context.Response.Write("{\"success\":true}"); return; } else { context.Response.Write("{\"success\":false}"); } } if (context.Request.Params["method"] == "modify") { modeobj.ID = Convert.ToInt32(context.Request.Params["id"]); if (ObjectBLL.Update(modeobj)) { context.Response.Write("{\"success\":true}"); } else { context.Response.Write("{\"success\":false}"); } } break; //修改管理员密码 case "UpPwd": AdminPage admininfo = new AdminPage(); Model.Angel_Admin modelpwd = admininfo.GetAdminInfo(); string OldPassword = AngelDESEncrypt.Encrypt(context.Request.Params["OldPasswrod"]); string NewPassword = AngelDESEncrypt.Encrypt(context.Request.Params["NewPassword"]); if (context.Request.Params["OldPasswrod"] == "" || context.Request.Params["OldPasswrod"] == null || context.Request.Params["NewPassword"] == "" || context.Request.Params["NewPassword"] == null) { context.Response.Write("{\"success\":false}"); return; } if (OldPassword == modelpwd.Password) { modelpwd.Password = NewPassword; if (ObjectBLL.Update(modelpwd)) { context.Response.Write("{\"success\":true}"); } else { context.Response.Write("{\"success\":false}"); } } else { context.Response.Write("{\"success\":false}"); } break; //删除信息 case "DelDB": string id = context.Request.Params["id"]; if (ObjectBLL.Delete(id)) { context.Response.Write("{\"success\":true}"); } else { context.Response.Write("{\"success\":false}"); } break; case "List": break; default: context.Response.Write("{\"success\":false}"); break; } }