Exemple #1
0
        public static bool AddUser(DomainUser user)
        {
            entry = oad.GetEntry(path, adminUser, password);
            if (oad.GetUserEntry(entry, user.Name) != null)
            {
                return(false);
            }
            string         filter  = "(&(objectclass=organizationalUnit)(ou=" + user.Department + "))";
            DirectoryEntry ouEntry = oad.GetOUEntry(entry, filter);

            if (ouEntry == null)
            {
                return(false);
            }
            if (!oad.AddAccount(ouEntry, user))
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
 public bool AddUserBasic(DomainUser user, string path, int IAuthType)
 {
     try
     {
         UserManager.AddUser(user.Name, IAuthType);
         string userName    = user.Name;
         string displayName = "RTX_NULL";
         int    gender      = -1;
         string mobile      = "RTX_NULL";
         string email       = "RTX_NULL";
         string phone       = "RTX_NULL";
         if (string.IsNullOrEmpty(user.DisplayName))
         {
             displayName = user.DisplayName;
         }
         if (string.IsNullOrEmpty(user.Mail))
         {
             email = user.Mail;
         }
         if (string.IsNullOrEmpty(user.TelephoneNumber))
         {
             mobile = user.TelephoneNumber;
             phone  = mobile;
         }
         if (string.IsNullOrEmpty(user.Initials))
         {
             gender = Convert.ToInt32(user.Initials);
         }
         UserManager.SetUserBasicInfo(userName, displayName, gender, mobile, email, phone, IAuthType);
         RtxDeptManager rdm = new RtxDeptManager();
         rdm.AddUserToDept(userName, null, path, false);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemple #3
0
 public bool EditAccount(DirectoryEntry userEntry, DomainUser user)
 {
     if (userEntry == null)
     {
         return(false);
     }
     //User.Properties["sAMAccountName"].Add(user.Name); //account
     //User.Properties["userPrincipalName"].Value = user.UserPrincipalName; //user logon name,[email protected]
     if (!string.IsNullOrEmpty(user.Company))
     {
         userEntry.Properties["company"].Value = user.Company;
     }
     if (!string.IsNullOrEmpty(user.Department))
     {
         userEntry.Properties["department"].Value = user.Department;
     }
     if (!string.IsNullOrEmpty(user.Description))
     {
         userEntry.Properties["description"].Value = user.Description;
     }
     if (!string.IsNullOrEmpty(user.DisplayName))
     {
         userEntry.Properties["displayName"].Value = user.DisplayName;
     }
     if (!string.IsNullOrEmpty(user.GivenName))
     {
         userEntry.Properties["givenName"].Value = user.GivenName;
     }
     if (!string.IsNullOrEmpty(user.Initials))
     {
         userEntry.Properties["initials"].Value = user.Initials;
     }
     if (!string.IsNullOrEmpty(user.Mail))
     {
         userEntry.Properties["mail"].Value = user.Mail;
     }
     //if (!string.IsNullOrEmpty(user.Name))
     //{
     //    userEntry.Properties["name"].Value = user.Name;
     //}
     if (!string.IsNullOrEmpty(user.PhysicalDeliveryOfficeName))
     {
         userEntry.Properties["physicalDeliveryOfficeName"].Value = user.PhysicalDeliveryOfficeName;
     }
     if (!string.IsNullOrEmpty(user.SN))
     {
         userEntry.Properties["sn"].Value = user.SN;
     }
     if (!string.IsNullOrEmpty(user.TelephoneNumber))
     {
         userEntry.Properties["telephoneNumber"].Value = user.TelephoneNumber;
     }
     try
     {
         userEntry.CommitChanges();
         //设置密码
         //反射调用修改密码的方法(注意端口号的问题  端口号会引起方法调用异常)
         userEntry.Invoke("SetPassword", new object[] { user.UserPwd });
         //默认设置新增账户启用
         //User.Properties["userAccountControl"].Value = 0x200;
         userEntry.CommitChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemple #4
0
 public bool EditAccount(DirectoryEntry userEntry, DomainUser user)
 {
     try
     {
         if (!string.IsNullOrEmpty(user.Company))
         {
             userEntry.Properties["company"].Value = user.Company;
         }
         if (!string.IsNullOrEmpty(user.Department))
         {
             userEntry.Properties["department"].Value = user.Department;
         }
         if (!string.IsNullOrEmpty(user.Description))
         {
             userEntry.Properties["description"].Value = user.Description;
         }
         if (!string.IsNullOrEmpty(user.DisplayName))
         {
             userEntry.Properties["displayName"].Value = user.DisplayName;
         }
         if (!string.IsNullOrEmpty(user.GivenName))
         {
             userEntry.Properties["givenName"].Value = user.GivenName;
         }
         //if (!string.IsNullOrEmpty(user.Initials))
         //{
         //    userEntry.Properties["initials"].Value = user.Initials;
         //}
         if (!string.IsNullOrEmpty(user.Mail))
         {
             userEntry.Properties["mail"].Value = user.Mail;
         }
         if (!string.IsNullOrEmpty(user.PhysicalDeliveryOfficeName))
         {
             userEntry.Properties["physicalDeliveryOfficeName"].Value = user.PhysicalDeliveryOfficeName;
         }
         if (!string.IsNullOrEmpty(user.SN))
         {
             userEntry.Properties["sn"].Value = user.SN;
         }
         if (!string.IsNullOrEmpty(user.TelephoneNumber))
         {
             userEntry.Properties["telephoneNumber"].Value = user.TelephoneNumber;
         }
         userEntry.Properties["initials"].Value = user.Gender;
         userEntry.CommitChanges();
         //设置密码
         //反射调用修改密码的方法(注意端口号的问题  端口号会引起方法调用异常)
         //if (!string.IsNullOrEmpty(user.UserPwd))
         //{
         //    userEntry.Invoke("SetPassword", new object[] { user.UserPwd });
         //    userEntry.CommitChanges();
         //    return false;
         //}
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemple #5
0
 public bool AddAccount(DirectoryEntry entry, DomainUser user)
 {
     try
     {
         DirectoryEntry NewUser = entry.Children.Add("CN=" + user.Name, "user");
         NewUser.Properties["sAMAccountName"].Add(user.Name);                     //account
         NewUser.Properties["userPrincipalName"].Value = user.Name + "@test.com"; //user logon name,[email protected]
         if (!string.IsNullOrEmpty(user.Company))
         {
             NewUser.Properties["company"].Value = user.Company;
         }
         if (!string.IsNullOrEmpty(user.Department))
         {
             NewUser.Properties["department"].Value = user.Department;
         }
         if (!string.IsNullOrEmpty(user.Description))
         {
             NewUser.Properties["description"].Value = user.Description;
         }
         if (!string.IsNullOrEmpty(user.DisplayName))
         {
             NewUser.Properties["displayName"].Value = user.DisplayName;
         }
         if (!string.IsNullOrEmpty(user.GivenName))
         {
             NewUser.Properties["givenName"].Value = user.GivenName;
         }
         if (!string.IsNullOrEmpty(user.Initials))
         {
             NewUser.Properties["initials"].Value = user.Initials;
         }
         if (!string.IsNullOrEmpty(user.Mail))
         {
             NewUser.Properties["mail"].Value = user.Mail;
         }
         if (!string.IsNullOrEmpty(user.Name))
         {
             NewUser.Properties["name"].Value = user.Name;
         }
         if (!string.IsNullOrEmpty(user.PhysicalDeliveryOfficeName))
         {
             NewUser.Properties["physicalDeliveryOfficeName"].Value = user.PhysicalDeliveryOfficeName;
         }
         if (!string.IsNullOrEmpty(user.SN))
         {
             NewUser.Properties["sn"].Value = user.SN;
         }
         if (!string.IsNullOrEmpty(user.TelephoneNumber))
         {
             NewUser.Properties["telephoneNumber"].Value = user.TelephoneNumber;
         }
         NewUser.Properties["initials"].Value = user.Gender;
         NewUser.CommitChanges();
         //设置密码
         //反射调用修改密码的方法(注意端口号的问题  端口号会引起方法调用异常)
         if (!string.IsNullOrEmpty(user.UserPwd))
         {
             NewUser.Invoke("SetPassword", new object[] { user.UserPwd });
             NewUser.Properties["userAccountControl"].Value = 0x200;
             //默认设置新增账户启用
             NewUser.CommitChanges();
         }
         else
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemple #6
0
        public bool AddEditRtxUser(DomainUser user, string path, int iAuthType)
        {
            string userName    = user.Name;
            string displayName = "RTX_NULL";
            int    gender      = -1;
            string mobile      = "RTX_NULL";
            string email       = "RTX_NULL";
            string phone       = "RTX_NULL";

            if (!string.IsNullOrEmpty(user.DisplayName))
            {
                displayName = user.DisplayName;
            }
            if (!string.IsNullOrEmpty(user.Mail))
            {
                email = user.Mail;
            }
            if (!string.IsNullOrEmpty(user.TelephoneNumber))
            {
                mobile = user.TelephoneNumber;
                phone  = mobile;
            }
            if (user.Gender == 0 || user.Gender == 1)
            {
                gender = user.Gender;
            }

            if (IsUserExist(user.Name))
            {
                if (!SetBasicRtxUser(userName, displayName, gender, mobile, email, phone, iAuthType))
                {
                    return(false);
                }
                if (!AddUserToDept(user.Name, GetUserDeptsName(user.Name), path, false))
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                if (AddRtxUser(user.Name, iAuthType))
                {
                    if (SetBasicRtxUser(userName, displayName, gender, mobile, email, phone, iAuthType))
                    {
                        if (!AddUserToDept(user.Name, null, path, false))
                        {
                            RemoveUser(user.Name);
                            return(false);
                        }
                        return(true);
                    }
                    else
                    {
                        RemoveUser(user.Name);
                        return(false);
                    }
                }
                else
                {
                    RemoveUser(user.Name);
                    return(false);
                }
            }
        }