Exemple #1
0
        //为注册的教师添加系部
        private void FillDepartOfTeacher()
        {
            ddlSchool.Items.Clear();

            if (rblRole.SelectedIndex == 0)
            {
                ddlSchool.Items.Add(WebPartObj.ADPath);
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    ArrayList depts = ADHelper.GetDeptsOfOU(WebPartObj.TeacherPath, WebPartObj.ADPath);
                    if (depts.Contains(WebPartObj.ADPath))
                    {
                        depts.Remove(WebPartObj.ADPath);
                    }
                    foreach (string dept in depts)
                    {
                        ddlSchool.Items.Add(dept);
                    }
                });
            }
            else
            {
            }
        }
Exemple #2
0
        private bool SaveAD(string userAccount, string txtName, string txtEmail, string txtTelephone, string txtPwd, string roleName, string schoolName, bool userEnabled)
        {
            bool retValue = false;

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    string domain   = ADHelper.Domain;
                    string strConst = HiddenField1.Value;
                    if (impersonateValidUser("administrator", domain, strConst.Substring(strConst.IndexOf(" ") + 1)))
                    {
                        string ouName = ddlSchool.SelectedItem.Text;// "iSmart";// System.Configuration.ConfigurationManager.AppSettings["adPath"];
                        if (rblRole.SelectedIndex == 0)
                        {
                            ouName = ADHelper.GetDirectoryEntryOfOU(WebPartObj.TeacherPath, ouName);
                        }
                        else
                        {
                            ouName = ADHelper.GetDirectoryEntryOfOU(WebPartObj.StudentPath, ouName);
                        }
                        retValue = ADHelper.AddUser(userAccount, txtName, txtEmail, txtTelephone, txtPwd, ouName, ddlSchool.SelectedItem.Text, schoolName, userEnabled);
                        undoImpersonation();
                    }
                    else
                    {
                        //Your impersonation failed. Therefore, include a fail-safe mechanism here.
                    }
                });
                return(retValue);
            }
            catch
            {
                return(false);
            }
        }