Ejemplo n.º 1
0
        private bool execADCmd()
        {
            bool Disabled = (!cbEnabled.Checked);

            if (adHelper.OU != tbOU.Text)
            {
                adHelper.OU = tbOU.Text.Trim();
            }
            ADUserDetail user = new ADUserDetail(tbUser.Text, Disabled, tbFirst.Text, tbLast.Text, tbEmail.Text, tbPwd.Text);
            string       cmd  = (string)cbCommand.SelectedItem;
            string       err  = "";

            switch (cmd.ToLower())
            {
            case "add":
                adHelper.AddUserByLogin(user, ref err);
                break;

            case "delete":
                adHelper.DeleteUserByLogin(user, ref err);
                break;

            case "disable":
                adHelper.DisableUserByLogin(user, ref err);
                break;

            case "enable":
                adHelper.EnableUserByLogin(user, ref err);
                break;

            case "import":
                break;

            case "update":
                adHelper.UpdateUserByLogin(user, false, ref err);
                break;

            case "list":
                List <ADUserDetail> userList = adHelper.GetUsers();
                if (userList.Count <= 0)
                {
                    rtbMsg.AppendText("No users found.");
                    return(false);
                }
                foreach (ADUserDetail u in userList)
                {
                    rtbMsg.AppendText("Username: "******", Disabled=" + u.AccountDisabled.ToString() + ", FirstName=" + u.FirstName + ",LastName=" + u.LastName + ", Email=" + u.EmailAddress + "\r\n");
                    rtbMsg.AppendText("===================================================================================================================\r\n");
                }
                break;

            default:
                MessageBox.Show("Unknown command.");
                return(false);
            }

            rtbMsg.AppendText("Successfully completed " + cmd + "!");
            return(true);
        }
Ejemplo n.º 2
0
        public bool UpdateUser(User user, int requestor, int reqId, ref string err)
        {
            err = "";
            bool logErr = false;

            try
            {
                if (CheckData(user, ref err) == false)
                {
                    int Event_id = 6027;
                    EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                    return(false);
                }
                ADUserDetail aduser = new ADUserDetail(user.Username, !user.Enabled, user.Firstname, user.Lastname, user.Email, user.Password);

                bool status = m_adHelper.UpdateUserByLogin(aduser, false, ref err);
                if (status == true)
                {
                    err = "";
                }
                else
                {
                    err += ", OU " + m_OU_Filter;
                    int Event_id = 6028;
                    EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                }
                return(status);
            }
            catch (Exception ex)
            {
                err = "Failed to update the user account, username="******", OU " + m_OU_Filter + ", Exception:" + ex.Message;
                int Event_id = 6029;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                return(false);
            }
            finally
            {
                if (logErr)
                {
                    int Event_id = 6030;
                    EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                }
            }
        }