コード例 #1
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }
        }
コード例 #2
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);
            _context.SaveChanges();
        }
コード例 #3
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
コード例 #4
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();
            new DefaultSiteSettingCreator(_context).Create();

            _context.SaveChanges();
        }
コード例 #5
0
        private void CreateDefaultTenant()
        {
            // Default tenant

            var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName);

            if (defaultTenant == null)
            {
                defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName);

                var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                if (defaultEdition != null)
                {
                    defaultTenant.EditionId = defaultEdition.Id;
                }

                _context.Tenants.Add(defaultTenant);
                _context.SaveChanges();
            }
        }
コード例 #6
0
        private void CreateSiteSetting()
        {
            var siteSetting = _context.SiteSettings.IgnoreQueryFilters().FirstOrDefault();

            if (siteSetting == null)
            {
                siteSetting = new SiteSetting
                {
                    SiteName     = "MRPanel",
                    Slogan       = "Easy CMS",
                    FacebookUrl  = "https://www.facebook.com/pazooki",
                    GithubUrl    = "https://github.com/iPazooki/MRPanel",
                    InstagramUrl = "https://www.instagram.com/ipazooki/",
                    TwitterUrl   = "https://twitter.com/iPazooki"
                };

                _context.SiteSettings.Add(siteSetting);

                _context.SaveChanges();
            }
        }
コード例 #7
0
        private void CreateHostRoleAndUsers()
        {
            // Admin role for host

            var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role for host

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new MRPanelAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = null,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRoleForHost.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user for host

            var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (adminUserForHost == null)
            {
                var user = new User
                {
                    TenantId         = null,
                    UserName         = AbpUserBase.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    IsActive         = true
                };

                user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe");
                user.SetNormalizedNames();

                adminUserForHost = _context.Users.Add(user).Entity;
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

                _context.SaveChanges();
            }
        }
コード例 #8
0
        private void CreateRolesAndUsers()
        {
            // Admin role

            var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == _tenantId && p.RoleId == adminRole.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new MRPanelAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = _tenantId,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRole.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user

            var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName);

            if (adminUser == null)
            {
                adminUser                  = User.CreateTenantAdminUser(_tenantId, "*****@*****.**");
                adminUser.Password         = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe");
                adminUser.IsEmailConfirmed = true;
                adminUser.IsActive         = true;

                _context.Users.Add(adminUser);
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();
            }
        }
コード例 #9
0
        private void CreateSiteContent()
        {
            // Create Home Pages
            var homePage = new Page
            {
                IsHomePage   = true,
                PageType     = PageType.Page,
                Title        = "Welcome",
                CreationTime = Clock.Now
            };

            _context.Pages.Add(homePage);
            _context.SaveChanges();

            // Create Widgets For Home Page
            var homePageContentWidget = new Widget
            {
                Page       = homePage,
                WidgetType = Domain.Enum.WidgetType.Paragraph,
                Order      = 1,
                Position   = Domain.Enum.Position.Justify,
                SizeType   = Domain.Enum.SizeType._100,
                Content    = "<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>"
            };

            var homePageHolderWidget = new Widget
            {
                Page       = homePage,
                WidgetType = Domain.Enum.WidgetType.Container,
                Order      = 1,
                Position   = Domain.Enum.Position.Justify,
                SizeType   = Domain.Enum.SizeType._100
            };

            var homePageLeftWidget = new Widget
            {
                Page       = homePage,
                WidgetType = Domain.Enum.WidgetType.Paragraph,
                Order      = 1,
                Position   = Domain.Enum.Position.Justify,
                SizeType   = Domain.Enum.SizeType._50,
                Parent     = homePageHolderWidget,
                Content    = "<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</p>"
            };

            var homePageRightWidget = new Widget
            {
                Page       = homePage,
                WidgetType = Domain.Enum.WidgetType.Paragraph,
                Order      = 1,
                Position   = Domain.Enum.Position.Justify,
                SizeType   = Domain.Enum.SizeType._50,
                Parent     = homePageHolderWidget,
                Content    = "<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>"
            };

            _context.Widgets.AddRange(new List <Widget> {
                homePageContentWidget,
                homePageHolderWidget,
                homePageLeftWidget,
                homePageRightWidget
            });
            _context.SaveChanges();

            // Create About Page
            var aboutPage = new Page
            {
                IsHomePage   = false,
                PageType     = PageType.Page,
                Title        = "About us",
                CreationTime = Clock.Now
            };

            _context.Pages.Add(aboutPage);
            _context.SaveChanges();

            // Create Widgets For About Page
            var AboutPageContentWidget = new Widget
            {
                Page       = aboutPage,
                WidgetType = Domain.Enum.WidgetType.Paragraph,
                Order      = 1,
                Position   = Domain.Enum.Position.Justify,
                SizeType   = Domain.Enum.SizeType._100,
                Content    = "<h2>Where does it come from?</h2><p>&nbsp;</p><p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.</p><p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from \"de Finibus Bonorum et Malorum\" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>"
            };

            _context.Widgets.Add(AboutPageContentWidget);
            _context.SaveChanges();

            //Create menu
            var homePageMenu = new Menu
            {
                IsExternal = false,
                PageId     = homePage.Id,
                Title      = "Home",
                Url        = "home"
            };

            var aboutPageMenu = new Menu
            {
                IsExternal = false,
                PageId     = aboutPage.Id,
                Title      = "About us",
                Url        = "about-us"
            };

            var subMenus = new Menu
            {
                IsExternal = false,
                Title      = "Sub Menus"
            };

            var sub_1_Menus = new Menu
            {
                IsExternal  = true,
                Parent      = subMenus,
                Title       = "Sub Menus-1",
                Description = "Quisque rutrum. Aenean imperdiet",
                Icon        = "ni ni-planet",
                Url         = "https://github.com/iPazooki"
            };

            var sub_2_Menus = new Menu
            {
                IsExternal  = true,
                Parent      = subMenus,
                Title       = "Sub Menus-2",
                Description = "Aenean leo ligula, porttitor",
                Icon        = "ni ni-spaceship",
                Url         = "https://www.linkedin.com/in/pazooki/"
            };

            _context.Menus.AddRange(new List <Menu> {
                homePageMenu,
                aboutPageMenu,
                subMenus,
                sub_1_Menus,
                sub_2_Menus
            });

            _context.SaveChanges();
        }