Esempio n. 1
0
        public ActionResult EditUser(DomainUser user)
        {
            string    filePath = Server.MapPath("~/ADConfig.xml");
            AdOperate ado      = new AdOperate(filePath);
            //ado.SetADConfig(user.ComName, filePath);
            DirectoryEntry entry   = ado.GetEntry();
            string         filter  = "(&(objectclass=organizationalUnit)(ou=" + user.Department + "))";
            DirectoryEntry ouEntry = ado.GetOUEntry(entry, filter);

            if (ouEntry == null)
            {
                return(Json(new AjaxResult {
                    Status = "error", Msg = "部门不存在"
                }));
            }
            DirectoryEntry userEntry = ado.GetUserEntry(entry, user.Name);

            if (userEntry == null)
            {
                return(Json(new AjaxResult {
                    Status = "error", Msg = "用户不存在"
                }));
            }
            if (!userEntry.Path.Contains(user.Department))
            {
                ado.UserMoveToOU(ouEntry, userEntry);
            }
            if (!ado.EditAccount(userEntry, user))
            {
                return(Json(new AjaxResult {
                    Status = "error", Msg = "编辑用户到域失败"
                }));
            }
            RtxManager rm = new RtxManager();

            string[] paths = ouEntry.Path.Replace("LDAP://192.168.31.134/", "").Replace(",DC=test,DC=com", "").Replace("OU=", "").Split(',');
            string   path  = "";

            for (int i = paths.Length - 1; i >= 0; i--)
            {
                path = path + paths[i] + @"\";
            }

            if (!rm.AddEditRtxUser(user, path, 1))
            {
                ado.GetUserEntry(entry, user.Name).DeleteTree();
                return(Json(new AjaxResult {
                    Status = "error", Msg = "rtx编辑用户失败"
                }));
            }
            return(Json(new AjaxResult {
                Status = "ok", Msg = "rtx编辑用户成功"
            }));
        }