public JsonResult SaveAdmin(int adminId, string lname, string rname, string pwd) { RetechWing.Models.Oper.SysAdmin admin; if (adminId == 0) { admin = new Models.Oper.SysAdmin(); admin.IsDelete = 0; admin.IsLock = 0; admin.LoginFailureCount = 0; admin.LoginName = lname; } else { admin = _adminManager.GetAdminById(adminId); } admin.Realname = rname; admin.Password = pwd.GetMd5(); if (adminId == 0) { _adminManager.AddAdmin(admin); } else { _adminManager.UpdateAdmin(admin); } return(Json(new { result = 1, msg = @RetechWing.LanguageResources.Exam.Exampaper.SaveSuccess }, JsonRequestBehavior.DenyGet)); }
/// <summary> /// Called when the query for the list of admin users is completed. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="QueryCompletedEventArgs"/> object containing the event data.</param> private void OnAdminsQuery(object sender, QueryCompletedEventArgs e) { var bundle = (Dictionary <string, object>)e.Data; var groups = (Dictionary <int, GroupInfo>)bundle["groups"]; var adminGroups = (Dictionary <int, List <GroupInfo> >)bundle["adminGroups"]; foreach (DataRow row in e.Results.Rows) { if (!int.TryParse(row.ItemArray.GetValue(0).ToString(), out var id)) { continue; } var identity = row.ItemArray.GetValue(1).ToString(); var flags = row.ItemArray.GetValue(2).ToString(); int.TryParse(row.ItemArray.GetValue(3).ToString(), out var immunity); if (adminGroups.ContainsKey(id)) { foreach (var group in adminGroups[id]) { flags += group.Flags; immunity = Math.Max(immunity, group.Immunity); } } AdminManager.AddAdmin(identity, immunity, flags); } }
protected void btnAdminSave_Click(object sender, EventArgs e) { AdminViewModel model = new AdminViewModel( int.Parse(employeeDropdownList.SelectedItem.Value), userNameTextBox.Text, passwordTextBox.Text, int.Parse(roleDropdownlistBox.SelectedItem.Value)); if (model.EmployeeId <= 0 || model.UserName == string.Empty || model.Password == string.Empty || model.ConfirmPassword == string.Empty || model.RoleId <= 0) { messageLabel.Text = "All The Fields Are Required."; } else { if (model.Password != model.ConfirmPassword) { messageLabel.Text = "Password Doesn't Match."; } else { if (_adminManager.AddAdmin(model.EmployeeId, model.UserName, model.Password, model.RoleId) == 1) { messageLabel.Text = "Admin Added Successfully."; } } } }
/// <summary> /// Called when the admin users query has completed. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="QueryCompletedEventArgs"/> object containing the event data.</param> private void OnAdminsQueryCompleted(object sender, QueryCompletedEventArgs e) { if (!e.Success) { this.adminRetryTimer = new Timer(this.retryTime.AsFloat * 1000); this.adminRetryTimer.Elapsed += this.OnAdminRetryTimerElapsed; this.adminRetryTimer.Enabled = true; return; } var groups = (Dictionary <string, GroupInfo>)e.Data; var admins = new List <SBCache.Admin>(); foreach (DataRow row in e.Results.Rows) { var identity = row.ItemArray.GetValue(0).ToString(); var groupName = row.ItemArray.GetValue(1).ToString(); var flags = row.ItemArray.GetValue(2).ToString(); int.TryParse(row.ItemArray.GetValue(3).ToString(), out var immunity); if (groups.TryGetValue(groupName, out var group)) { flags += group.Flags; immunity = Math.Max(immunity, group.Immunity); } admins.Add(new SBCache.Admin(identity, flags, immunity)); AdminManager.AddAdmin(identity, immunity, flags); } this.cache.SetAdminList(admins, 60 * 5); }
/// <inheritdoc/> public override void OnReloadAdmins() { if (!this.enableAdmins.AsBool || this.adminRetryTimer != null) { return; } if (this.cache.GetAdmins(out var list, out var expired) && !expired) { foreach (var admin in list) { AdminManager.AddAdmin(admin.Identity, admin.Immunity, admin.Flags); } return; } this.LoadAdmins(); }
protected void btnAdd_Click(object sender, EventArgs e) { try { Admin us = new Admin(); us.AdminName = txtUserName.Text; //输入要添加的管理员的名字 us.AdminPassword = txtPassword.Text; //输入要添加的管理员的密码 int i = AdminManager.AddAdmin(us); //找到dal层的插入的方法 if (i == 1) //判断管理员表中是否影响了一行数据,如果是执行成功 下一操作 { Page.ClientScript.RegisterClientScriptBlock(typeof(Object), "alert", "<script>alert('添加成功!');</script>"); } } catch (Exception) { Page.ClientScript.RegisterClientScriptBlock(typeof(Object), "alert", "<script>alert('数据库中已存在相同用户名!');</script>"); } }
protected void AddAdminButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(AdminID.Text)) { Response.Write("<script>alert('ID를 입력해주세요.');</script>"); } else if (string.IsNullOrEmpty(AdminName.Text)) { Response.Write("<script>alert('[이름 - 직책]을 입력해주세요.');</script>"); } else { AdminManager.AddAdmin(new Models.Admin { ID = AdminID.Text, Name = AdminName.Text }); Response.Redirect("/admin/AdminManagement.aspx"); } }
public void SavePassword(Admin admin) { admin.AdminPassword = Crypto.HashPassword(admin.AdminPassword); am.AddAdmin(admin); }
/// <summary> /// Loads the admin users from the Admins.xml file. /// </summary> private void LoadAdmins() { if (!File.Exists(ConfigPath)) { this.CreateConfig(); } var xml = new XmlDocument(); try { xml.Load(ConfigPath); } catch (XmlException e) { this.LogError($"Failed reading admin configuration from {ConfigPath}: {e.Message}"); return; } var groups = new Dictionary <string, GroupInfo>(); var groupsNodes = xml.GetElementsByTagName("Groups"); if (groupsNodes.Count > 0) { foreach (XmlElement node in ((XmlElement)groupsNodes[0]).GetElementsByTagName("Group")) { if (!node.HasAttribute("Name")) { continue; } var name = node.GetAttribute("Name"); if (groups.ContainsKey(name)) { continue; } var immunity = 1; if (node.HasAttribute("Immunity")) { int.TryParse(node.GetAttribute("Immunity"), out immunity); } var flags = string.Empty; if (node.HasAttribute("Flags")) { flags = node.GetAttribute("Flags"); } groups.Add(name, new GroupInfo(name, immunity, flags)); } } var adminsNodes = xml.GetElementsByTagName("Admins"); if (adminsNodes.Count > 0) { foreach (XmlElement node in ((XmlElement)adminsNodes[0]).GetElementsByTagName("Admin")) { if (!node.HasAttribute("AuthId")) { continue; } var authId = node.GetAttribute("AuthId"); var immunity = 1; if (node.HasAttribute("Immunity")) { int.TryParse(node.GetAttribute("Immunity"), out immunity); } var flags = string.Empty; if (node.HasAttribute("Flags")) { flags = node.GetAttribute("Flags"); } if (node.HasAttribute("Groups")) { foreach (var groupName in node.GetAttribute("Groups").Split(',')) { if (groups.ContainsKey(groupName)) { GroupInfo group = groups[groupName]; immunity = Math.Max(immunity, group.Immunity); flags += group.Flags; } } } AdminManager.AddAdmin(authId, immunity, flags); } } if (this.watcher == null) { this.watcher = new FileSystemWatcher(Path.GetDirectoryName(ConfigPath), Path.GetFileName(ConfigPath)) { NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite, }; this.watcher.Changed += this.OnAdminFileChanged; this.watcher.Deleted += this.OnAdminFileChanged; this.watcher.Renamed += this.OnAdminFileChanged; this.watcher.EnableRaisingEvents = true; } }