private bool DoEdit(int oid) { ht_manager manager = db.ht_manager.FirstOrDefault(x => x.id == oid); if (manager == null) { return(false); } manager.roleid = Convert.ToInt32(ddlRoleId.SelectedValue); var role = db.ht_manager_role.FirstOrDefault(x => x.id == Manager.roleid); if (role != null) { manager.roletype = role.roletype; } manager.islock = cbIsLock.Checked ? 0 : 1; //判断密码是否更改 if (txtPassword.Text.Trim() != defaultpassword) { //获取用户已生成的salt作为密钥加密 manager.password = EncryptUtil.DesEncrypt(txtPassword.Text.Trim(), manager.salt); } manager.nickname = txtRealName.Text; manager.mobile = txtTelephone.Text; db.SaveChanges(); AddAdminLog(HTEnums.ActionEnum.Edit.ToString(), "修改管理员:" + manager.username); return(true); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { admin = Manager; } }
private bool DoAdd() { ht_manager manager = db.ht_manager.FirstOrDefault(x => x.username == txtUserName.Text); if (manager != null) { return(false); } var role = db.ht_manager_role.FirstOrDefault(x => x.id == Manager.roleid); if (role != null) { ht_manager model = new ht_manager { roleid = Convert.ToInt32(ddlRoleId.SelectedValue), islock = cbIsLock.Checked ? 0 : 1, username = txtUserName.Text, salt = Utils.GetCheckCode(10), roletype = role.roletype, mobile = txtTelephone.Text, nickname = txtRealName.Text, addtime = DateTime.Now }; model.password = EncryptUtil.DesEncrypt(txtPassword.Text.Trim(), model.salt); db.ht_manager.Add(model); db.SaveChanges(); } return(true); }
//批量删除 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("manager_list", HTEnums.ActionEnum.Delete.ToString()); int sucCount = 0; int errorCount = 0; for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { ht_manager model = db.ht_manager.FirstOrDefault(x => x.id == id); if (model != null) { db.ht_manager.Remove(model); db.SaveChanges(); sucCount++; } else { errorCount++; } } } AddAdminLog(HTEnums.ActionEnum.Delete.ToString(), "删除管理员" + sucCount + "条,失败" + errorCount + "条"); //记录日志 JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Utils.CombUrlTxt("manager_list.aspx", "keywords={0}", keywords)); }
/// <summary> /// 检查管理员权限 /// </summary> /// <param name="navname">菜单名称</param> /// <param name="actiontype">操作类型</param> public void ChkAdminLevelRejson(string navname, string actiontype) { ht_manager model = Manager; bool result = Exist(Convert.ToInt32(model.roleid), navname, actiontype); if (!result) { Response.Write("{\"status\":0,\"msg\":\"您没有管理该页面的权限,请勿非法操作!\"}"); Response.End(); } }
/// <summary> /// 检查管理员权限 /// </summary> /// <param name="navname">菜单名称</param> /// <param name="actiontype">操作类型</param> public void ChkAdminLevel(string navname, string actiontype) { ht_manager model = Manager; bool result = Exist(Convert.ToInt32(model.roleid), navname, actiontype); if (!result) { string msgbox = "parent.jsdialog(\"错误提示\", \"您没有管理该页面的权限,请勿非法进入!\", \"back\")"; Response.Write("<script type=\"text/javascript\">" + msgbox + "</script>"); Response.End(); } }
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; } ht_manager temp = db.ht_manager.FirstOrDefault(x => x.username == userName); if (temp == null) { msgtip.InnerHtml = "用户名或密码有误,请重试!"; return; } string pwd = EncryptUtil.DesEncrypt(txtPassword.Text, temp.salt); //temp = db.ht_manager.FirstOrDefault(x => x.username == userName && x.password == pwd); temp = db.ht_manager.FirstOrDefault(x => x.username == userName); if (temp == null) { msgtip.InnerHtml = "用户名或密码有误,请重试!"; return; } if (temp.islock == 1) { msgtip.InnerHtml = "用户已被禁用 , 登录失败 ! "; return; } Session[HTKeys.SESSION_ADMIN_INFO] = temp; Session.Timeout = 45; Utils.WriteCookie("RememberName", temp.username, 14400); Utils.WriteCookie("AdminName", "HT", temp.username); Utils.WriteCookie("AdminPwd", "HT", temp.password); Response.Redirect("index.aspx"); }
private void RoleTypeBind() { ht_manager model = Manager; ddlRoleType.Items.Clear(); ddlRoleType.Items.Add(new ListItem("请选择类型...", "")); if (model.roletype < 2) { ddlRoleType.Items.Add(new ListItem("超级用户", "1")); } ddlRoleType.Items.Add(new ListItem("系统用户", "2")); }
private void ShowInfo(int oid) { ht_manager model = db.ht_manager.FirstOrDefault(x => x.id == oid); ddlRoleId.SelectedValue = model.roleid.ToString(); cbIsLock.Checked = model.islock == 0; txtUserName.Text = model.username; txtUserName.Attributes.Remove("ajaxurl"); if (!string.IsNullOrEmpty(model.password)) { txtPassword.Attributes["value"] = txtPassword1.Attributes["value"] = defaultpassword; } txtRealName.Text = model.nickname; txtTelephone.Text = model.mobile; }
/// <summary> /// 后台用户名验证 /// </summary> private void manager_validate(HttpContext context) { string username = HTRequest.GetString("param"); string oldname = HTRequest.GetString("old_name"); if (string.IsNullOrEmpty(username)) { context.Response.Write(NavInfo("用户名不可为空", "n")); return; } if (string.Equals(username, oldname, StringComparison.CurrentCultureIgnoreCase)) { context.Response.Write(NavInfo("该用户名可使用", "y")); return; } ht_manager user = _db.ht_manager.FirstOrDefault(x => x.username == username); context.Response.Write(user != null ? NavInfo("该用户名已被占用,请更换", "n") : NavInfo("该用户名可使用", "y")); }
/// <summary> /// 检查管理员权限 /// </summary> /// <param name="navname">菜单名称</param> /// <param name="actiontype">操作类型</param> public bool ChkAdminLevelBool(string navname, string actiontype) { ht_manager model = Manager; return(Exist(Convert.ToInt32(model.roleid), navname, actiontype)); }