Beispiel #1
0
        /// <summary>
        /// زمانیکه ایمیل ساخته شد ، در هنگام تایید ، نیاز است کمله عبور دانشجو،
        /// به کلمه اصلی تغییر کند
        /// </summary>
        /// <returns></returns>
        public bool ChangePassEmail_AfterCreateEmail(string stcode, string reqid)
        {
            // add Reset pass
            DataTable           DT  = GetStudentInfoFromAmozesh(stcode);
            Email_ClassBusiness emb = new Email_ClassBusiness();

            string UserName = DT.Rows[0]["Email_Address"].ToString();
            string Password = DT.Rows[0]["Password"].ToString();

            // وقتی پسورد را می خواهیم از دیتابیس بخوانیم ، نیاز به دکد کردن داریم
            //EncryptionClass ThisKey = new EncryptionClass(Password);
            Password = CommonBusiness.DecryptPass(Password);
            return(ADB.ResetPassword(UserName, Password, reqid));
        }
        public bool CreateUser_ActiveDirectory(string stcode, out string error)
        {
            try
            {
                ActiveDirectoryDTO  ActiveDirectoryDTO = new ActiveDirectoryDTO();
                Email_ClassBusiness emb = new Email_ClassBusiness();

                DataTable DT = emb.GetStudentInfoFromAmozesh(stcode);
                string    level;
                if (DT.Rows[0]["magh"].ToString() == "1")
                {
                    level = "کارشناسی";
                }
                else if (DT.Rows[0]["magh"].ToString() == "5")
                {
                    level = "ارشد";
                }
                else
                {
                    level = "دکتری";
                }

                ActiveDirectoryDTO.SamAccountName = DT.Rows[0]["Email_Address"].ToString();
                ActiveDirectoryDTO.Uid            = DT.Rows[0]["Email_Address"].ToString();
                ActiveDirectoryDTO.GivenName      = DT.Rows[0]["name"].ToString();
                ActiveDirectoryDTO.DisplayName    = DT.Rows[0]["name"].ToString() + " " + DT.Rows[0]["family"].ToString();
                ActiveDirectoryDTO.Name           = DT.Rows[0]["name"].ToString();
                ActiveDirectoryDTO.sn             = DT.Rows[0]["family"].ToString();   //+ DT.Rows[0]["family"].ToString();
                ActiveDirectoryDTO.Description    = stcode;
                ActiveDirectoryDTO.Company        = DT.Rows[0]["nameresh"].ToString(); // +"-" + Field;
                ActiveDirectoryDTO.Department     = level;
                ActiveDirectoryDTO.Password       = "******";
                ActiveDirectoryDTO.FieldCode      = int.Parse(DT.Rows[0]["fresh_ID"].ToString());
                return(ActiveDirectoryBusiness.CreateUser(ActiveDirectoryDTO, out error));
            }
            catch (Exception ex)
            {
                error = "error112:" + ex.Message;
                return(false);
            }



            //Email_ClassBusiness emb = new Email_ClassBusiness();
            //DataTable DT =emb.GiveStudent_Active(stcode);
            //string Field;
            //if (DT.Rows[0]["magh"].ToString() == "1")
            //    Field = "کارشناسی";
            //else
            //    Field = "ارشد";
            //string ldapPath = "192.168.1.2/OU=rdv,OU=iauec,DC=iauec,DC=LOCAL";
            //string oGUID = string.Empty;

            //try
            //{
            //    string connectionPrefix = "LDAP://" + ldapPath;
            //    DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
            //    dirEntry.Username = "******";
            //    dirEntry.Password = "";
            //    oGUID = dirEntry.Guid.ToString(); // وقتی بخواهیم چک کنیم که آیا به درستی وصل شده به سرور

            //    DirectoryEntry newUser = dirEntry.Children.Add("CN=" + DT.Rows[0]["Email_Address"].ToString(), "user");
            //    newUser.Properties["samAccountName"].Value = DT.Rows[0]["Email_Address"].ToString();
            //    newUser.Properties["uid"].Value = DT.Rows[0]["Email_Address"].ToString();
            //    newUser.Properties["givenName"].Value = DT.Rows[0]["name"].ToString();
            //    newUser.Properties["description"].Value = stcode;
            //    newUser.Properties["company"].Value = DT.Rows[0]["nameresh"].ToString() + "-" + Field;
            //    newUser.Properties["displayName"].Value = DT.Rows[0]["family"].ToString(); //Farsi
            //    newUser.Properties["name"].Value = DT.Rows[0]["family"].ToString() + DT.Rows[0]["family"].ToString();
            //    newUser.CommitChanges();
            //    oGUID = newUser.Guid.ToString();
            //    //newUser.Invoke("SetPassword", new object[] { DT.Rows[0]["Password"].ToString() });
            //    newUser.Invoke("SetPassword", new object[] { "t123@456" });
            //    newUser.CommitChanges();
            //    newUser.Properties["userAccountControl"].Value = 0x200;
            //    newUser.CommitChanges();
            //    dirEntry.Close();
            //    newUser.Close();
            //    return true;
            //}
            //catch (System.DirectoryServices.DirectoryServicesCOMException E)
            //{
            //    oGUID = E.Message.ToString();
            //    return false;
            //}
        }