Exemple #1
0
            //public bool EntryExists(string login)
            //{
            //    bool exits = true;
            //    try
            //    {
            //        string ldapSearchFilter = "cn=" + login.Trim();
            //        message += ldapSearchFilter;
            //        SearchRequest searchRequest = new SearchRequest
            //                                        ("",
            //                                          ldapSearchFilter,
            //                                          System.DirectoryServices.Protocols.SearchScope.Subtree,
            //                                          null);
            //        SearchResponse searchResponse =
            //                    (SearchResponse)Connection.SendRequest(searchRequest);

            //        message += String.Format("\r\nSearch Response Entries:{0}",
            //                    searchResponse.Entries.Count);
            //        if (searchResponse.Entries.Count > 0)
            //        {
            //            exits = true;
            //        }
            //        else
            //        {
            //            exits = false;
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        message += String.Format("\nUnexpected exception occured:\n\t{0}: {1}",
            //                          e.GetType().Name, e.Message);
            //        exits = false;
            //    }
            //    return exits;
            //}



            public string CreateEntry(INovellOrganizationContactPerson person)
            {
                // LdapAttributeSet attributeSet = new LdapAttributeSet();
                // attributeSet.Add(new LdapAttribute(
                //                     "objectclass", "inetOrgPerson"));
                ///attributeSet.Add(new LdapAttribute("cn",
                // new string[] { person.Login }));

                //attributeSet.Add(new LdapAttribute("givenname",
                //                     person.FirstName));
                //attributeSet.Add(new LdapAttribute("sn", person.Surname));
                //attributeSet.Add(new LdapAttribute("mail", person.Email));
                //attributeSet.Add(new LdapAttribute("userpassword", person.Password));
                // string dn = "cn=" + person.Login + ",ou=Users,o=Alien";
                //LdapEntry newEntry = new LdapEntry(dn, attributeSet);
                //Connection.Add(newEntry);
                //return newEntry.DN;


                string containerName = "ou=Users,o=Alien";
                // string login = "******";

                string     dn           = "cn=" + person.Login + "," + containerName;
                string     dirClassType = "inetOrgPerson";
                AddRequest addRequest   = new AddRequest(dn, dirClassType);

                addRequest.Attributes.Add(new DirectoryAttribute("cn", new string[] { person.Login }));
                addRequest.Attributes.Add(new DirectoryAttribute("givenname", person.FirstName));
                addRequest.Attributes.Add(new DirectoryAttribute("sn", person.Surname));
                addRequest.Attributes.Add(new DirectoryAttribute("mail", person.Email));
                addRequest.Attributes.Add(new DirectoryAttribute("userpassword", person.Password));
                AddResponse addResponse = (AddResponse)connection.SendRequest(addRequest);

                return(dn);
            }
Exemple #2
0
        public INovellOrganizationContactPerson CreateOrganization(INovellOrganizationContactPerson person)
        {
            string DN = "";

            foreach (string serverAddress in ServerAddresses)
            {
                try
                {
                    using (NovellProvider novell = new NovellProvider(serverAddress, 636))
                    {
                        novell.Connect();
                        novell.Bind(Properties.Settings.Default.NovellDN, Properties.Settings.Default.NovellPassword);
                        person.Login = novell.GenerateUniqueAlienCN(person.Login);
                        bool entryExist = novell.EntryExists(person.Login);
                        if (!entryExist)
                        {
                            DN = novell.CreateEntry(person);
                        }
                        if (DN != "")
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    continue;
                }
            }
            return(person);
        }
Exemple #3
0
        public async Task SendEmailWithCredentials(INovellOrganizationContactPerson novellPerson, string userId)
        {
            string letterText = File.ReadAllText(request.AppPath() + "/HtmlMailFile/letter.html");

            letterText = letterText.Replace("NEW_USER_LOGIN", novellPerson.Login);
            letterText = letterText.Replace("NEW_USER_PASSWORD", novellPerson.Password);
            await UserManager.SendEmailAsync(userId, "Регистрация в кабинете клиента GTI", letterText);
        }
Exemple #4
0
        public async Task <IHttpActionResult> SimpleRegisterOrganizationContactPerson(int organizationContactPersonId)
        {
            if (organizationContactPersonId != 0)
            {
                OrganizationContactPersonView person = null;

                UnitOfWork unitOfWork = new UnitOfWork(factory);
                person = unitOfWork.OrganizationContactPersonsViewRepository.Get(d => d.Id == organizationContactPersonId)
                         .FirstOrDefault();

                if (person == null || person.Deleted == true)
                {
                    return(BadRequest("Organization contact person doesn't exist"));
                }
                if (person.IsRegistered == true)
                {
                    return(BadRequest("Organization contact person is already registered as an API  user"));
                }
                if (person.Email == null || person.Email == "")
                {
                    return(BadRequest("Organization contact person email is empty"));
                }
                INovellOrganizationContactPerson novellPerson;
                try
                {
                    novellPerson = new NovellOrganizationContactPerson(person);
                    // novellPerson.Login = novell.GenerateLogin(novellPerson.Login);
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }

                INovellOrganizationContactPerson personCreated = novell.CreateOrganization(novellPerson);
                if (personCreated != null)
                {
                    bool dbResult = context.CreateOrganization(novellPerson.Login, novellPerson.Password);
                    if (dbResult)
                    {
                        ApplicationUser user = new ApplicationUser()
                        {
                            UserName = novellPerson.Login,
                            Email    = novellPerson.Email,
                            //TableName = "OrganizationContactPerson",
                            //TableId = organizationContactPersonId
                        };
                        try
                        {
                            IdentityResult result = await UserManager.CreateAsync(user, novellPerson.Password);

                            if (!result.Succeeded)
                            {
                                return(GetErrorResult(result));
                            }
                            else
                            {
                                IdentityResult roleResult = await UserManager.AddToRoleAsync(user.Id, "Organization");

                                if (!roleResult.Succeeded)
                                {
                                    return(GetErrorResult(roleResult));
                                }

                                bool rightsResult = context.GrantRightsToOrganization(user.Id);
                                if (rightsResult)
                                {
                                    await SendEmailWithCredentials(novellPerson, user.Id);

                                    return(Ok());
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            string m = e.Message;
                            return(BadRequest("AspNetUser has not been created"));
                        }
                    }
                    else
                    {
                        return(BadRequest("Database login has not been created"));
                    }
                }
                else
                {
                    return(BadRequest("eDirectory login has not been created"));
                }
            }
            return(BadRequest("Wrong organization contact person"));
        }
Exemple #5
0
 INovellOrganizationContactPerson INovelleDirectory.CreateOrganization(INovellOrganizationContactPerson person)
 {
     throw new NotImplementedException();
 }