private Boolean AddAuthentication(Person person, dtoBaseProfile profile, dtoImportSettings settings, ProfileAttributesRow row, AuthenticationProvider provider)
        {
            Boolean result = false;

            if (provider.ProviderType == AuthenticationProviderType.Internal)
            {
                InternalLoginInfo info = InternalService.GenerateUserInfo(person, profile.Login, profile.Password, (InternalAuthenticationProvider)provider, false);
                result = (info != null);
            }
            else
            {
                dtoExternalCredentials credentials = new dtoExternalCredentials();
                if (lm.Comol.Core.DomainModel.PermissionHelper.CheckPermissionSoft((int)provider.IdentifierFields, (int)IdentifierField.longField))
                {
                    long identifierLong = 0;
                    long.TryParse(row.GetCellValue(ProfileAttributeType.externalId), out identifierLong);
                    credentials.IdentifierLong = identifierLong;
                }
                if (lm.Comol.Core.DomainModel.PermissionHelper.CheckPermissionSoft((int)provider.IdentifierFields, (int)IdentifierField.stringField))
                {
                    credentials.IdentifierString = row.GetCellValue(ProfileAttributeType.externalId);
                }

                if (UrlService.VerifyDuplicateExternalLoginInfo(person, provider, credentials) == ProfilerError.none)
                {
                    ExternalLoginInfo externaLogin = UrlService.AddExternalProfile(person, provider, credentials);
                    result = (externaLogin != null);
                }
            }
            return(result);
        }
 public void InitView(dtoImportSettings settings)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout();
     }
     else
     {
         View.SendMailToUsers = true;
         View.DisplayMail(Service.GetProfileTypeMailTemplateAttributes(settings));
         View.isInitialized = true;
     }
 }
Exemple #3
0
 public void InitView(ProfileExternalResource source, dtoImportSettings settings)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout();
     }
     else
     {
         View.AutoGenerateLogin = settings.AutoGenerateLogin;
         lm.Comol.Core.BaseModules.ProviderManagement.dtoBaseProvider provider = Service.GetAuthenticationProvider(UserContext.Language.Id, settings.IdProvider);
         Service.AnalyzeItems(source, settings);
         List <ProfileExternalResource> items = new List <ProfileExternalResource>();
         items.Add(source);
         View.LoadItems(items, GetInvalidItems(source), settings.IdProfileType, (provider == null) ? "" : provider.Translation.Name);
     }
 }
        private void GenerateBaseProfile(dtoBaseProfile profile, dtoImportSettings settings, ProfileAttributesRow row, AuthenticationProviderType type, Language language)
        {
            profile.AuthenticationProvider = type;
            profile.IdDefaultProvider      = settings.IdProvider;
            profile.IdProfileType          = settings.IdProfileType;
            profile.IdLanguage             = language.Id;
            profile.LanguageName           = language.Name;
            profile.Mail    = row.GetCellValue(ProfileAttributeType.mail).Trim();
            profile.Name    = row.GetCellValue(ProfileAttributeType.name).Trim();
            profile.Surname = row.GetCellValue(ProfileAttributeType.surname).Trim();

            profile.Sector = row.GetCellValue(ProfileAttributeType.sector);
            profile.Job    = row.GetCellValue(ProfileAttributeType.job);

            if (profile.PersonInfo == null)
            {
                profile.PersonInfo = new PersonInfo();
            }

            string birthOn = row.GetCellValue(ProfileAttributeType.birthDate);


            DateTime birthDate = DefaultBirthDate;

            try
            {
                birthDate = System.DateTime.Parse(birthOn);
            }
            catch (Exception)
            {
                birthDate = DefaultBirthDate;
            }
            profile.PersonInfo.BirthDate = birthDate;


            profile.PersonInfo.BirthPlace = row.GetCellValue(ProfileAttributeType.birthPlace);

            if (!String.IsNullOrEmpty(profile.Name))
            {
                profile.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(profile.Name);
            }
            if (!String.IsNullOrEmpty(profile.Surname))
            {
                profile.Surname = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(profile.Surname);
            }

            if (type == AuthenticationProviderType.Internal)
            {
                profile.Password = (settings.AddPassword) ? row.GetCellValue(ProfileAttributeType.password) : lm.Comol.Core.DomainModel.Helpers.RandomKeyGenerator.GenerateRandomKey(6, 10, true, true, false);
                profile.Login    = (settings.AutoGenerateLogin) ? row.GetCellValue(ProfileAttributeType.autoGeneratedLogin) : row.GetCellValue(ProfileAttributeType.login);

                if (string.IsNullOrEmpty(profile.Login))
                {
                    profile.Login = InternalService.GenerateInternalLogin(profile.Name, profile.Surname);
                }
                else if (!InternalService.isInternalUniqueLogin(profile.Login))
                {
                    profile.Login = InternalService.GenerateInternalLogin(profile.Name, profile.Surname);
                }
            }
            else
            {
                profile.Login = row.GetCellValue(ProfileAttributeType.externalId);
            }
            profile.ShowMail = false;

            if (!string.IsNullOrEmpty(profile.Surname))
            {
                profile.FirstLetter = profile.Surname[0].ToString().ToLower();
            }

            profile.TaxCode = row.GetCellValue(ProfileAttributeType.taxCode);
            //if (settings.AddTaxCode)
            //    profile.TaxCode = row.GetCellValue(ProfileAttributeType.taxCode);
            if (String.IsNullOrEmpty(profile.TaxCode))
            {
                profile.TaxCode = InternalService.GenerateRandomTaxCode();
            }

            while (!InternalService.isUniqueTaxCode(profile.TaxCode))
            {
                profile.TaxCode = InternalService.GenerateRandomTaxCode();
            }
        }
        private List <Person> CreateProfiles(dtoImportSettings settings, Int32 idDefaultOrganization, ProfileExternalResource selectedItems, List <dtoImportedProfile> createdProfiles, List <dtoBaseProfile> notCreatedProfiles)
        {
            List <Person>          profiles = new List <Person>();
            Language               language = CurrentManager.GetDefaultLanguage();
            AuthenticationProvider provider = Service.GetAuthenticationProvider(settings.IdProvider);

            if (provider != null && language != null)
            {
                Boolean created  = false;
                Int32   idPerson = 0;
                Int32   index    = 1;
                foreach (ProfileAttributesRow row in selectedItems.Rows)
                {
                    dtoBaseProfile baseItem = null;
                    switch (settings.IdProfileType)
                    {
                    case (int)UserTypeStandard.ExternalUser:
                        dtoExternal externalUser = CreateExternal(row);
                        baseItem = externalUser;
                        break;

                    case (int)UserTypeStandard.Company:
                        dtoCompany company = CreateCompanyUser(row);
                        baseItem = company;
                        break;

                    case (int)UserTypeStandard.Employee:
                        dtoEmployee employee = CreateEmployee(row);
                        baseItem = employee;
                        break;

                    default:
                        baseItem = new dtoBaseProfile();
                        break;
                    }
                    created = false;

                    if (baseItem != null)
                    {
                        GenerateBaseProfile(baseItem, settings, row, provider.ProviderType, GetUserLanguage(row, language));
                        if (InternalService.isUniqueMail(baseItem.Mail))
                        {
                            PersonInfo info = GeneratePersonInfo(row, baseItem);
                            idPerson = View.AddUserProfile(baseItem, info, idDefaultOrganization, provider);
                            if (idPerson > 0)
                            {
                                Person person = CurrentManager.GetPerson(idPerson);
                                if (person != null)
                                {
                                    created = AddAuthentication(person, baseItem, settings, row, provider);
                                    if (created)
                                    {
                                        Service.SetDefaultProvider(provider.Id, person.Id);
                                    }
                                    profiles.Add(person);
                                    createdProfiles.Add(new dtoImportedProfile()
                                    {
                                        Profile = baseItem, Info = info
                                    });
                                }
                            }
                        }
                        if (!created)
                        {
                            notCreatedProfiles.Add(baseItem);
                        }
                        View.UpdateProfileCreation(0, index, created, baseItem.DisplayName);
                    }
                    else
                    {
                        View.UpdateProfileCreation(0, index, created, " // ");
                    }
                    index++;
                }
            }
            return(profiles);
        }
        public void ImportProfiles(
            dtoImportSettings settings,
            Int32 defaultIdOrganization,
            List <Int32> allOrganizationsId,
            ProfileExternalResource selectedItems,
            List <dtoNewProfileSubscription> subscriptions,
            Boolean sendMailToUsers,
            lm.Comol.Core.Mail.dtoMailContent mailContent)
        {
            List <ProfileImportAction> actions = new List <ProfileImportAction>();

            View.PreviousStep = ProfileImportStep.None;

            actions.Add(ProfileImportAction.Create);

            if (allOrganizationsId.Where(id => id != defaultIdOrganization).Any())
            {
                actions.Add(ProfileImportAction.AddToOtherOrganizations);
            }

            actions.Add(ProfileImportAction.AddToCommunities);

            if (sendMailToUsers)
            {
                actions.Add(ProfileImportAction.SendMail);
            }

            View.SetupProgressInfo(actions.Count, selectedItems.Rows.Count);

            // Create profiles
            List <dtoBaseProfile>      notCreatedProfiles       = new List <dtoBaseProfile>();
            List <dtoImportedProfile>  createdProfiles          = new List <dtoImportedProfile>();
            List <Person>              profiles                 = CreateProfiles(settings, defaultIdOrganization, selectedItems, createdProfiles, notCreatedProfiles);
            Dictionary <Int32, String> notaddedToOrganizations  = new Dictionary <Int32, String>();
            Dictionary <Int32, String> notSubscribedCommunities = new Dictionary <Int32, String>();
            List <dtoImportedProfile>  notSentMail              = new List <dtoImportedProfile>();

            if (profiles != null && profiles.Count > 0)
            {
                AddProfilesToOrganizations(defaultIdOrganization, allOrganizationsId, profiles, subscriptions.Where(s => s.IdCommunityType == 0).ToList(), notaddedToOrganizations);
                AddProfilesToCommunities(actions, profiles, subscriptions.Where(s => s.IdCommunityType != 0).ToList(), notSubscribedCommunities);
                if (sendMailToUsers)
                {
                    SendMailToProfiles(actions, createdProfiles, mailContent, Service.GetProfileTypeMailTemplateAttributes(settings), notSentMail);
                }
            }

            View.UpdateSourceItems(View.CurrentSource);

            Int32 itemsToSelect = View.ItemsToSelect;

            View.PreviousStep = (itemsToSelect > 0) ? ProfileImportStep.ItemsSelctor : ProfileImportStep.None;

            if (notCreatedProfiles.Count == 0 && notaddedToOrganizations.Count == 0 && notSubscribedCommunities.Count == 0 && notSentMail.Count == 0)
            {
                View.isCompleted = (itemsToSelect == 0);
                View.DisplayImportedProfiles(profiles.Count, itemsToSelect);
            }
            else
            {
                View.DisplayImportError(profiles.Count, notCreatedProfiles, notaddedToOrganizations, notSubscribedCommunities, notSentMail);
            }
        }