Пример #1
0
        public SiteManager(
            SiteContext currentSite,
            SiteEvents siteEventHandlers,
            ISiteCommands siteCommands,
            ISiteQueries siteQueries,
            IUserCommands userCommands,
            IUserQueries userQueries,
            SiteDataProtector dataProtector,
            IHttpContextAccessor contextAccessor,
            ILogger <SiteManager> logger,
            IOptions <MultiTenantOptions> multiTenantOptionsAccessor,
            IOptions <SiteConfigOptions> setupOptionsAccessor,
            CacheHelper cacheHelper
            )
        {
            _commands           = siteCommands;
            _queries            = siteQueries;
            _userCommands       = userCommands;
            _userQueries        = userQueries;
            _multiTenantOptions = multiTenantOptionsAccessor.Value;
            _setupOptions       = setupOptionsAccessor.Value;
            _context            = contextAccessor?.HttpContext;
            _dataProtector      = dataProtector;
            _log = logger;

            //resolver = siteResolver;
            _currentSite   = currentSite;
            _cacheHelper   = cacheHelper;
            _eventHandlers = siteEventHandlers;
        }
Пример #2
0
        public SiteManager(
            SiteSettings currentSite,
            ISiteCommands siteCommands,
            ISiteQueries siteQueries,
            IUserCommands userCommands,
            IUserQueries userQueries,
            SiteDataProtector dataProtector,
            IHttpContextAccessor contextAccessor,
            ILogger <SiteManager> logger,
            IOptions <MultiTenantOptions> multiTenantOptionsAccessor,
            IOptions <SiteConfigOptions> setupOptionsAccessor,
            CacheHelper cacheHelper
            )
        {
            commands           = siteCommands;
            queries            = siteQueries;
            this.userCommands  = userCommands;
            this.userQueries   = userQueries;
            multiTenantOptions = multiTenantOptionsAccessor.Value;
            setupOptions       = setupOptionsAccessor.Value;
            _context           = contextAccessor?.HttpContext;
            this.dataProtector = dataProtector;
            log = logger;

            //resolver = siteResolver;
            siteSettings     = currentSite;
            this.cacheHelper = cacheHelper;
        }
Пример #3
0
        public SiteManager(
            SiteContext currentSite,
            ISiteCommands siteCommands,
            ISiteQueries siteQueries,
            IUserCommands userCommands,
            IUserQueries userQueries,
            SiteDataProtector dataProtector,
            IHttpContextAccessor contextAccessor,
            ILogger<SiteManager> logger,
            IOptions<MultiTenantOptions> multiTenantOptionsAccessor,
            IOptions<SiteConfigOptions> setupOptionsAccessor,
            CacheHelper cacheHelper
            )
        {

            commands = siteCommands;
            queries = siteQueries;
            this.userCommands = userCommands;
            this.userQueries = userQueries;
            multiTenantOptions = multiTenantOptionsAccessor.Value;
            setupOptions = setupOptionsAccessor.Value;
            _context = contextAccessor?.HttpContext;
            this.dataProtector = dataProtector;
            log = logger;

            //resolver = siteResolver;
            siteSettings = currentSite;
            this.cacheHelper = cacheHelper;
        }
Пример #4
0
        private static async Task EnsureData(
            ISiteQueries siteQueries,
            ISiteCommands siteCommands,
            IUserQueries userQueries,
            IUserCommands userCommands,
            IGeoQueries geoQueries,
            IGeoCommands geoCommands,
            IBasicQueries<SiteRole> roleQueries,
            IBasicQueries<SiteUser> userBasic
            
            )
        {
            
            int count = await geoQueries.GetCountryCount();
            if (count == 0)
            {
                foreach (GeoCountry c in InitialData.BuildCountryList())
                {
                    await geoCommands.Add(c);
                }

                foreach (GeoZone c in InitialData.BuildStateList())
                {
                    await geoCommands.Add(c);
                }
            }
            
            count = await siteQueries.GetCount();
            SiteSettings newSite = null;
            
            Guid siteId = Guid.Empty;
            if (count == 0)
            {
                // create first site
                newSite = InitialData.BuildInitialSite();
                await siteCommands.Create(newSite);
                siteId = newSite.Id;
                
            }
            else if(count == 1)
            {
                var allSites = await siteQueries.GetList().ConfigureAwait(false);
                var site = allSites[0];
                if (site != null) siteId = site.Id;
            }
            else
            {
                return;
            }

            // ensure roles
            //var projectId = await projectResolver.ResolveProjectId();
            var projectId = siteId.ToString(); ;


            count = await roleQueries.GetCountAsync(projectId);
            if (count == 0)
            {
                var adminRole = InitialData.BuildAdminRole();
                adminRole.SiteId = siteId;
                await userCommands.CreateRole(adminRole);
                
                var roleAdminRole = InitialData.BuildRoleAdminRole();
                roleAdminRole.SiteId = siteId;
                await userCommands.CreateRole(roleAdminRole);
                
                var contentAdminRole = InitialData.BuildContentAdminsRole();
                contentAdminRole.SiteId = siteId;
                await userCommands.CreateRole(contentAdminRole);

                var authenticatedUserRole = InitialData.BuildAuthenticatedRole();
                authenticatedUserRole.SiteId = siteId;
                await userCommands.CreateRole(authenticatedUserRole);
                
            }

            // ensure admin user
            count = await userBasic.GetCountAsync(projectId);

            if (count == 0)
            {
                var role = await userQueries.FetchRole(newSite.Id, "Administrators");
                
                if (role != null)
                {
                    var adminUser = InitialData.BuildInitialAdmin();
                    adminUser.SiteId = siteId;
                    await userCommands.Create(adminUser);
                    
                    await userCommands.AddUserToRole(siteId, role.Id, adminUser.Id);

                    role = await userQueries.FetchRole(siteId, "Authenticated Users");
                    
                    if (role != null)
                    {
                        await userCommands.AddUserToRole(siteId, role.Id, adminUser.Id);
                    }
                }
                
            }

        }
Пример #5
0
        private static async Task EnsureData(
            ISiteQueries siteQueries,
            ISiteCommands siteCommands,
            IUserQueries userQueries,
            IUserCommands userCommands,
            IGeoQueries geoQueries,
            IGeoCommands geoCommands,
            IBasicQueries <SiteRole> roleQueries,
            IBasicQueries <SiteUser> userBasic,
            IProjectResolver projectResolver
            )
        {
            int count = await geoQueries.GetCountryCount();

            if (count == 0)
            {
                foreach (GeoCountry c in InitialData.BuildCountryList())
                {
                    await geoCommands.Add(c);
                }

                foreach (GeoZone c in InitialData.BuildStateList())
                {
                    await geoCommands.Add(c);
                }
            }

            //count = await geoQueries.GetLanguageCount();
            //if (count == 0)
            //{
            //    foreach (Language c in InitialData.BuildLanguageList())
            //    {
            //        await geoCommands.Add(c);
            //    }
            //}

            var all = await geoQueries.GetAllCurrencies();

            count = all.Count;
            if (count == 0)
            {
                foreach (Currency c in InitialData.BuildCurrencyList())
                {
                    await geoCommands.Add(c);
                }
            }

            count = await siteQueries.GetCount();

            SiteSettings newSite = null;

            if (count == 0)
            {
                // create first site
                newSite = InitialData.BuildInitialSite();
                await siteCommands.Create(newSite);
            }

            // ensure roles
            var projectId = await projectResolver.ResolveProjectId();

            count = await roleQueries.GetCountAsync(projectId);

            if (count == 0)
            {
                var adminRole = InitialData.BuildAdminRole();
                adminRole.SiteId = newSite.Id;
                await userCommands.CreateRole(adminRole);

                var roleAdminRole = InitialData.BuildRoleAdminRole();
                roleAdminRole.SiteId = newSite.Id;
                await userCommands.CreateRole(roleAdminRole);

                var contentAdminRole = InitialData.BuildContentAdminsRole();
                contentAdminRole.SiteId = newSite.Id;
                await userCommands.CreateRole(contentAdminRole);

                var authenticatedUserRole = InitialData.BuildAuthenticatedRole();
                authenticatedUserRole.SiteId = newSite.Id;
                await userCommands.CreateRole(authenticatedUserRole);
            }

            // ensure admin user
            count = await userBasic.GetCountAsync(projectId);

            if (count == 0)
            {
                var role = await userQueries.FetchRole(newSite.Id, "Administrators");

                if (role != null)
                {
                    var adminUser = InitialData.BuildInitialAdmin();
                    adminUser.SiteId = newSite.Id;
                    await userCommands.Create(adminUser);

                    await userCommands.AddUserToRole(role.Id, adminUser.Id);

                    role = await userQueries.FetchRole(newSite.Id, "Authenticated Users");

                    if (role != null)
                    {
                        await userCommands.AddUserToRole(role.Id, adminUser.Id);
                    }
                }
            }
        }
Пример #6
0
        private static async Task EnsureData(
            ISiteQueries siteQueries,
            ISiteCommands siteCommands,
            IUserQueries userQueries,
            IUserCommands userCommands,
            IGeoQueries geoQueries,
            IGeoCommands geoCommands,
            IBasicQueries <SiteRole> roleQueries,
            IBasicQueries <SiteUser> userBasic

            )
        {
            int count = await geoQueries.GetCountryCount();

            if (count == 0)
            {
                foreach (GeoCountry c in InitialData.BuildCountryList())
                {
                    await geoCommands.Add(c);
                }

                foreach (GeoZone c in InitialData.BuildStateList())
                {
                    await geoCommands.Add(c);
                }
            }

            count = await siteQueries.GetCount();

            SiteSettings newSite = null;

            Guid siteId = Guid.Empty;

            if (count == 0)
            {
                // create first site
                newSite = InitialData.BuildInitialSite();
                await siteCommands.Create(newSite);

                siteId = newSite.Id;
            }
            else if (count == 1)
            {
                var allSites = await siteQueries.GetList().ConfigureAwait(false);

                var site = allSites[0];
                if (site != null)
                {
                    siteId = site.Id;
                }
            }
            else
            {
                return;
            }

            // ensure roles
            //var projectId = await projectResolver.ResolveProjectId();
            var projectId = siteId.ToString();;


            count = await roleQueries.GetCountAsync(projectId);

            if (count == 0)
            {
                var adminRole = InitialData.BuildAdminRole();
                adminRole.SiteId = siteId;
                await userCommands.CreateRole(adminRole);

                var roleAdminRole = InitialData.BuildRoleAdminRole();
                roleAdminRole.SiteId = siteId;
                await userCommands.CreateRole(roleAdminRole);

                var contentAdminRole = InitialData.BuildContentAdminsRole();
                contentAdminRole.SiteId = siteId;
                await userCommands.CreateRole(contentAdminRole);

                var authenticatedUserRole = InitialData.BuildAuthenticatedRole();
                authenticatedUserRole.SiteId = siteId;
                await userCommands.CreateRole(authenticatedUserRole);
            }

            // ensure admin user
            count = await userBasic.GetCountAsync(projectId);

            if (count == 0)
            {
                var role = await userQueries.FetchRole(newSite.Id, "Administrators");

                if (role != null)
                {
                    var adminUser = InitialData.BuildInitialAdmin();
                    adminUser.SiteId         = siteId;
                    adminUser.CanAutoLockout = false;
                    await userCommands.Create(adminUser);

                    await userCommands.AddUserToRole(siteId, role.Id, adminUser.Id);

                    role = await userQueries.FetchRole(siteId, "Authenticated Users");

                    if (role != null)
                    {
                        await userCommands.AddUserToRole(siteId, role.Id, adminUser.Id);
                    }
                }
            }
        }