private void btnChangePassword_Click(object sender, EventArgs e) { if (lbUsers.SelectedItem == null) { MessageBox.Show("Please select a user"); return; } UserPrincipal insUserPrincipal = (UserPrincipal)lbUsers.SelectedItem; UserPassword password = new UserPassword(); frmProperties insFrmProperties = new frmProperties(password, ActionTypes.Save); insFrmProperties.ShowDialog(); if (insFrmProperties.DialogResult == DialogResult.OK) { try { insUserPrincipal.SetPassword(password.Password); MessageBox.Show("Password changed."); } catch (Exception ex) { MessageBox.Show(ex.Message); } ListUsers(); } }
private void btnEditGroup_Click(object sender, EventArgs e) { if (lbGroups.SelectedItem == null) { MessageBox.Show("Please select a group"); return; } GroupPrincipal insGroupPrincipal = (GroupPrincipal)lbGroups.SelectedItem; frmProperties insFrmProperties = new frmProperties(insGroupPrincipal, ActionTypes.Save); insFrmProperties.ShowDialog(); if (insFrmProperties.DialogResult == DialogResult.OK) { try { insGroupPrincipal.Save(); insGroupPrincipal.Dispose(); MessageBox.Show("Group updated."); } catch (Exception ex) { MessageBox.Show(ex.Message); } ListGroups(); } }
private void btnFilterUsers_Click(object sender, EventArgs e) { UserPrincipal insUserPrincipal = new UserPrincipal(insPrincipalContext); frmProperties insFrmProperties = new frmProperties(insUserPrincipal, ActionTypes.Filter); insFrmProperties.ShowDialog(); if (insFrmProperties.DialogResult == DialogResult.OK) { SearchUsers(insUserPrincipal); } }
private void btnListUsersGroups_Click(object sender, EventArgs e) { if (lbUsers.SelectedItem == null) { MessageBox.Show("Please select a user"); return; } UserPrincipal insUserPrincipal = (UserPrincipal)lbUsers.SelectedItem; List <Principal> insListPrincipal = new List <Principal>(); foreach (Principal p in insUserPrincipal.GetGroups()) { insListPrincipal.Add(p); } frmProperties insFrmProperties = new frmProperties(insListPrincipal, ActionTypes.None); insFrmProperties.ShowDialog(); }
private void btnRemoveUserFromAGroup_Click(object sender, EventArgs e) { if (lbUsers.SelectedItem == null) { MessageBox.Show("Please select a user"); return; } UserPrincipal insUserPrincipal = (UserPrincipal)lbUsers.SelectedItem; UserGroup group = new UserGroup(); frmProperties insFrmProperties = new frmProperties(group, ActionTypes.Save); insFrmProperties.ShowDialog(); if (insFrmProperties.DialogResult == DialogResult.OK) { try { GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName); if (groupPrincipal == null) { MessageBox.Show("Group not found."); return; } if (!groupPrincipal.Members.Contains(insPrincipalContext, IdentityType.SamAccountName, insUserPrincipal.SamAccountName)) { MessageBox.Show(insUserPrincipal.Name + " is not a member of group " + group.GroupName); return; } groupPrincipal.Members.Remove(insUserPrincipal); groupPrincipal.Save(); MessageBox.Show("User removed from group."); } catch (Exception ex) { MessageBox.Show(ex.Message); } ListUsers(); } }
private void btnNewGroup_Click(object sender, EventArgs e) { GroupPrincipal insGroupPrincipal = new GroupPrincipal(insPrincipalContext); frmProperties insFrmProperties = new frmProperties(insGroupPrincipal, ActionTypes.Save); insFrmProperties.ShowDialog(); if (insFrmProperties.DialogResult == DialogResult.OK) { try { insGroupPrincipal.Save(); insGroupPrincipal.Dispose(); MessageBox.Show("Group created."); } catch (Exception ex) { MessageBox.Show(ex.Message); } ListGroups(); } }