-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADUser.cs
117 lines (99 loc) · 3.25 KB
/
ADUser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.DirectoryServices;
// TODO: Convert this to use the newer System.DirectoryServices.AccountManagement approach.
// https://learn.microsoft.com/en-us/dotnet/api/system.directoryservices.accountmanagement?view=dotnet-plat-ext-7.0&redirectedfrom=MSDN
//
namespace User_Administration_Dashboard
{
class ADUser : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private DirectoryEntry _directoryEntry;
public ADUser(DirectoryEntry directoryEntry)
{
_directoryEntry = directoryEntry;
}
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
public string FirstName
{
get { return _directoryEntry.Properties["givenname"].Value?.ToString(); }
}
public string LastName
{
get { return _directoryEntry.Properties["sn"].Value?.ToString(); }
}
public string EmailAddress
{
get { return _directoryEntry.Properties["mail"].Value?.ToString(); }
}
public string City
{
get { return _directoryEntry.Properties["l"].Value?.ToString(); }
}
public string State
{
get { return _directoryEntry.Properties["st"].Value?.ToString(); }
}
public string Title
{
get { return _directoryEntry.Properties["title"].Value?.ToString(); }
}
public string Department
{
get { return _directoryEntry.Properties["department"].Value?.ToString(); }
}
public string Manager
{
get {
string manager = _directoryEntry.Properties["manager"].Value?.ToString();
if (manager != null)
{
manager = manager.Split(',')[0];
manager = manager.Split('=')[1];
}
else
{
manager = "Not set!";
}
return manager;
}
}
public bool Lockedout
{
get
{
return false;
return Convert.ToBoolean(_directoryEntry.InvokeGet("IsAccountLocked"));
//return lockouttime is null ? false : true;
}
}
public ObservableCollection<string> Groups
{
get
{
ObservableCollection<string> groups = new ObservableCollection<string>();
object g = _directoryEntry.Invoke("Groups");
foreach (object ob in (IEnumerable)g)
{
DirectoryEntry group = new DirectoryEntry(ob);
string groupName = group.Name;
groupName = groupName.Split(',')[0];
groupName = groupName.Split('=')[1];
groups.Add(groupName);
}
return groups;
}
}
}
}