示例#1
0
        public override void ConfigureServices(IServiceCollection services)
        {
            // Add ILookupNormalizer as Singleton because it is needed by Users
            services.TryAddSingleton <ILookupNormalizer, UpperInvariantLookupNormalizer>();

            services.AddScoped <IAuditTrailManager, AuditTrailManager>();

            services
            .AddScoped <IDisplayManager <AuditTrailEvent>, DisplayManager <AuditTrailEvent> >()
            .AddScoped <IDisplayDriver <AuditTrailEvent>, AuditTrailEventDisplayDriver>();

            services.AddSingleton <IAuditTrailIdGenerator, AuditTrailIdGenerator>();

            services.Configure <StoreCollectionOptions>(o => o.Collections.Add(AuditTrailEvent.Collection));

            services.AddScoped <IDataMigration, Migrations>();
            services.AddSingleton <IIndexProvider, AuditTrailEventIndexProvider>();
            services.AddSingleton <IBackgroundTask, AuditTrailBackgroundTask>();

            services.AddScoped <IPermissionProvider, Permissions>();
            services.AddScoped <INavigationProvider, AuditTrailAdminMenu>();
            services.AddScoped <INavigationProvider, AuditTrailSettingsAdminMenu>();

            services.AddScoped <IDisplayDriver <ISite>, AuditTrailSettingsDisplayDriver>();
            services.AddScoped <IDisplayDriver <ISite>, AuditTrailTrimmingSettingsDisplayDriver>();

            services.AddScoped <IDisplayManager <AuditTrailIndexOptions>, DisplayManager <AuditTrailIndexOptions> >()
            .AddScoped <IDisplayDriver <AuditTrailIndexOptions>, AuditTrailOptionsDisplayDriver>();

            services.AddScoped <IAuditTrailAdminListQueryService, DefaultAuditTrailAdminListQueryService>();

            services.AddSingleton <IAuditTrailAdminListFilterParser>(sp =>
            {
                var filterProviders = sp.GetServices <IAuditTrailAdminListFilterProvider>();
                var builder         = new QueryEngineBuilder <AuditTrailEvent>();
                foreach (var provider in filterProviders)
                {
                    provider.Build(builder);
                }

                var parser = builder.Build();

                return(new DefaultAuditTrailAdminListFilterParser(parser));
            });

            services.AddTransient <IAuditTrailAdminListFilterProvider, DefaultAuditTrailAdminListFilterProvider>();

            services.AddOptions <AuditTrailOptions>();

            services.Configure <AuditTrailAdminListOptions>(options =>
            {
                options
                .ForSort("time-desc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderByDescending(i => i.CreatedUtc))
                         .WithSelectListItem <Startup>((S, opt, model) => new SelectListItem(S["Newest"], opt.Value, model.Sort == String.Empty))
                         .AsDefault())

                .ForSort("time-asc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderBy(i => i.CreatedUtc))
                         .WithSelectListItem <Startup>((S, opt, model) => new SelectListItem(S["Oldest"], opt.Value, model.Sort == opt.Value)))

                .ForSort("category-asc-time-desc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderBy(i => i.Category).ThenByDescending(i => i.CreatedUtc))
                         .WithSelectListItem <Startup>((S, opt, model) => new SelectListItem(S["Category"], opt.Value, model.Sort == opt.Value)))

                .ForSort("category-asc-time-asc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderBy(i => i.Category).ThenBy(i => i.CreatedUtc)))

                .ForSort("category-desc-time-desc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderByDescending(i => i.Category).ThenByDescending(i => i.CreatedUtc)))

                .ForSort("category-desc-time-asc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderByDescending(i => i.Category).ThenBy(i => i.CreatedUtc)))

                .ForSort("event-asc-time-desc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderBy(i => i.Name).ThenByDescending(i => i.CreatedUtc))
                         .WithSelectListItem <Startup>((S, opt, model) => new SelectListItem(S["Event"], opt.Value, model.Sort == opt.Value)))

                .ForSort("event-asc-time-asc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderBy(i => i.Name).ThenBy(i => i.CreatedUtc)))

                .ForSort("event-desc-time-desc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderByDescending(i => i.Name).ThenByDescending(i => i.CreatedUtc)))

                .ForSort("event-desc-time-asc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderByDescending(i => i.Name).ThenBy(i => i.CreatedUtc)))

                .ForSort("user-asc-time-asc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderBy(i => i.NormalizedUserName).ThenBy(i => i.CreatedUtc))
                         .WithSelectListItem <Startup>((S, opt, model) => new SelectListItem(S["User"], opt.Value, model.Sort == opt.Value)))

                .ForSort("user-desc-time-desc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderByDescending(i => i.NormalizedUserName).ThenByDescending(i => i.CreatedUtc)))

                .ForSort("user-desc-time-asc", b => b
                         .WithQuery((val, query) => query.With <AuditTrailEventIndex>().OrderByDescending(i => i.NormalizedUserName).ThenBy(i => i.CreatedUtc)));
            });
        }
示例#2
0
        public override void ConfigureServices(IServiceCollection services)
        {
            services.Configure <UserOptions>(userOptions =>
            {
                var configuration = ShellScope.Services.GetRequiredService <IShellConfiguration>();
                configuration.GetSection("OrchardCore_Users").Bind(userOptions);
            });

            // Add ILookupNormalizer as Singleton because it is needed by UserIndexProvider
            services.TryAddSingleton <ILookupNormalizer, UpperInvariantLookupNormalizer>();

            // Adds the default token providers used to generate tokens for reset passwords, change email
            // and change telephone number operations, and for two factor authentication token generation.
            services.AddIdentity <IUser, IRole>(options =>
            {
                // Specify OrchardCore User requirements.
                // A user name cannot include an @ symbol, i.e. be an email address
                // An email address must be provided, and be unique.
                options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._+";
                options.User.RequireUniqueEmail        = true;
            })
            .AddDefaultTokenProviders();

            // Configure the authentication options to use the application cookie scheme as the default sign-out handler.
            // This is required for security modules like the OpenID module (that uses SignOutAsync()) to work correctly.
            services.AddAuthentication(options => options.DefaultSignOutScheme = IdentityConstants.ApplicationScheme);

            services.TryAddScoped <UserStore>();
            services.TryAddScoped <IUserStore <IUser> >(sp => sp.GetRequiredService <UserStore>());
            services.TryAddScoped <IUserRoleStore <IUser> >(sp => sp.GetRequiredService <UserStore>());
            services.TryAddScoped <IUserPasswordStore <IUser> >(sp => sp.GetRequiredService <UserStore>());
            services.TryAddScoped <IUserEmailStore <IUser> >(sp => sp.GetRequiredService <UserStore>());
            services.TryAddScoped <IUserSecurityStampStore <IUser> >(sp => sp.GetRequiredService <UserStore>());
            services.TryAddScoped <IUserLoginStore <IUser> >(sp => sp.GetRequiredService <UserStore>());
            services.TryAddScoped <IUserClaimStore <IUser> >(sp => sp.GetRequiredService <UserStore>());
            services.TryAddScoped <IUserAuthenticationTokenStore <IUser> >(sp => sp.GetRequiredService <UserStore>());

            services.ConfigureApplicationCookie(options =>
            {
                var userOptions = ShellScope.Services.GetRequiredService <IOptions <UserOptions> >();

                options.Cookie.Name = "orchauth_" + HttpUtility.UrlEncode(_tenantName);

                // Don't set the cookie builder 'Path' so that it uses the 'IAuthenticationFeature' value
                // set by the pipeline and comming from the request 'PathBase' which already ends with the
                // tenant prefix but may also start by a path related e.g to a virtual folder.

                options.LoginPath        = "/" + userOptions.Value.LoginPath;
                options.LogoutPath       = "/" + userOptions.Value.LogoffPath;
                options.AccessDeniedPath = "/Error/403";
            });

            services.AddSingleton <IIndexProvider, UserIndexProvider>();
            services.AddSingleton <IIndexProvider, UserByRoleNameIndexProvider>();
            services.AddSingleton <IIndexProvider, UserByLoginInfoIndexProvider>();
            services.AddSingleton <IIndexProvider, UserByClaimIndexProvider>();
            services.AddScoped <IDataMigration, Migrations>();

            services.AddScoped <IUserService, UserService>();
            services.AddScoped <IUserClaimsPrincipalFactory <IUser>, DefaultUserClaimsPrincipalProviderFactory>();
            services.AddScoped <IUserClaimsProvider, EmailClaimsProvider>();
            services.AddSingleton <IUserIdGenerator, DefaultUserIdGenerator>();

            services.AddScoped <IAuthorizationHandler, UserAuthorizationHandler>();

            services.AddScoped <IMembershipService, MembershipService>();
            services.AddScoped <ISetupEventHandler, SetupEventHandler>();
            services.AddScoped <ICommandHandler, UserCommands>();
            services.AddScoped <IRoleRemovedEventHandler, UserRoleRemovedEventHandler>();
            services.AddScoped <IExternalLoginEventHandler, ScriptExternalLoginEventHandler>();

            services.AddScoped <IPermissionProvider, Permissions>();
            services.AddScoped <INavigationProvider, AdminMenu>();

            services.AddScoped <IDisplayDriver <ISite>, LoginSettingsDisplayDriver>();

            services.AddScoped <IDisplayDriver <User>, UserDisplayDriver>();
            services.AddScoped <IDisplayDriver <User>, UserRoleDisplayDriver>();
            services.AddScoped <IDisplayDriver <User>, UserInformationDisplayDriver>();
            services.AddScoped <IDisplayDriver <User>, UserButtonsDisplayDriver>();

            services.AddScoped <IThemeSelector, UsersThemeSelector>();

            services.AddScoped <IRecipeEnvironmentProvider, RecipeEnvironmentSuperUserProvider>();

            services.AddScoped <IUsersAdminListQueryService, DefaultUsersAdminListQueryService>();

            services.AddScoped <IDisplayDriver <UserIndexOptions>, UserOptionsDisplayDriver>();

            services.AddSingleton <IUsersAdminListFilterParser>(sp =>
            {
                var filterProviders = sp.GetServices <IUsersAdminListFilterProvider>();
                var builder         = new QueryEngineBuilder <User>();
                foreach (var provider in filterProviders)
                {
                    provider.Build(builder);
                }

                var parser = builder.Build();

                return(new DefaultUsersAdminListFilterParser(parser));
            });

            services.AddTransient <IUsersAdminListFilterProvider, DefaultUsersAdminListFilterProvider>();

            services.AddScoped <IUserEventHandler, UserDisabledEventHandler>();
        }
示例#3
0
        public override void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IAnchorTag, ContentAnchorTag>();

            services.Configure <LiquidViewOptions>(o =>
            {
                o.LiquidViewParserConfiguration.Add(parser => parser.RegisterParserTag("contentitem", parser.ArgumentsListParser, ContentItemTag.WriteToAsync));
            });

            services.Configure <TemplateOptions>(o =>
            {
                o.MemberAccessStrategy.Register <ContentItem>();
                o.MemberAccessStrategy.Register <ContentElement>();
                o.MemberAccessStrategy.Register <ShapeViewModel <ContentItem> >();
                o.MemberAccessStrategy.Register <ContentTypePartDefinition>();
                o.MemberAccessStrategy.Register <ContentPartFieldDefinition>();
                o.MemberAccessStrategy.Register <ContentFieldDefinition>();
                o.MemberAccessStrategy.Register <ContentPartDefinition>();

                o.Filters.AddFilter("display_text", DisplayTextFilter.DisplayText);

                o.Scope.SetValue("Content", new ObjectValue(new LiquidContentAccessor()));
                o.MemberAccessStrategy.Register <LiquidContentAccessor, LiquidPropertyAccessor>("ContentItemId", (obj, context) =>
                {
                    var liquidTemplateContext = (LiquidTemplateContext)context;

                    return(new LiquidPropertyAccessor(liquidTemplateContext, async(contentItemId, context) =>
                    {
                        var contentManager = context.Services.GetRequiredService <IContentManager>();

                        return FluidValue.Create(await contentManager.GetAsync(contentItemId), context.Options);
                    }));
                });

                o.MemberAccessStrategy.Register <LiquidContentAccessor, LiquidPropertyAccessor>("ContentItemVersionId", (obj, context) =>
                {
                    var liquidTemplateContext = (LiquidTemplateContext)context;

                    return(new LiquidPropertyAccessor(liquidTemplateContext, async(contentItemVersionId, context) =>
                    {
                        var contentManager = context.Services.GetRequiredService <IContentManager>();

                        return FluidValue.Create(await contentManager.GetVersionAsync(contentItemVersionId), context.Options);
                    }));
                });

                o.MemberAccessStrategy.Register <LiquidContentAccessor, LiquidPropertyAccessor>("Latest", (obj, context) =>
                {
                    var liquidTemplateContext = (LiquidTemplateContext)context;

                    return(new LiquidPropertyAccessor(liquidTemplateContext, (name, context) =>
                    {
                        return GetContentByHandleAsync(context, name, true);
                    }));
                });

                o.MemberAccessStrategy.Register <LiquidContentAccessor, FluidValue>((obj, name, context) => GetContentByHandleAsync((LiquidTemplateContext)context, name));

                async Task <FluidValue> GetContentByHandleAsync(LiquidTemplateContext context, string handle, bool latest = false)
                {
                    var contentHandleManager = context.Services.GetRequiredService <IContentHandleManager>();

                    var contentItemId = await contentHandleManager.GetContentItemIdAsync(handle);

                    if (contentItemId == null)
                    {
                        return(NilValue.Instance);
                    }

                    var contentManager = context.Services.GetRequiredService <IContentManager>();

                    var contentItem = await contentManager.GetAsync(contentItemId, latest ? VersionOptions.Latest : VersionOptions.Published);
                    return(FluidValue.Create(contentItem, context.Options));
                }
            })
            .AddLiquidFilter <DisplayUrlFilter>("display_url")
            .AddLiquidFilter <BuildDisplayFilter>("shape_build_display")
            .AddLiquidFilter <ContentItemFilter>("content_item_id")
            .AddLiquidFilter <FullTextFilter>("full_text");

            services.AddContentManagement();
            services.AddContentManagementDisplay();
            services.AddScoped <IPermissionProvider, Permissions>();
            services.AddScoped <IPermissionProvider, ContentTypePermissions>();
            services.AddScoped <IAuthorizationHandler, ContentTypeAuthorizationHandler>();
            services.AddScoped <IShapeTableProvider, Shapes>();
            services.AddScoped <INavigationProvider, AdminMenu>();
            services.AddScoped <IContentDisplayDriver, ContentsDriver>();
            services.AddScoped <IContentHandler, ContentsHandler>();
            services.AddRecipeExecutionStep <ContentStep>();

            services.AddScoped <IContentItemIndexHandler, FullTextContentIndexHandler>();
            services.AddScoped <IContentItemIndexHandler, AspectsContentIndexHandler>();
            services.AddScoped <IContentItemIndexHandler, DefaultContentIndexHandler>();
            services.AddScoped <IContentHandleProvider, ContentItemIdHandleProvider>();
            services.AddScoped <IContentItemIndexHandler, ContentItemIndexCoordinator>();

            services.AddScoped <IDataMigration, Migrations>();

            // Common Part
            services.AddContentPart <CommonPart>()
            .UseDisplayDriver <DateEditorDriver>()
            .UseDisplayDriver <OwnerEditorDriver>();

            services.AddScoped <IContentTypePartDefinitionDisplayDriver, CommonPartSettingsDisplayDriver>();

            // FullTextAspect
            services.AddScoped <IContentTypeDefinitionDisplayDriver, FullTextAspectSettingsDisplayDriver>();
            services.AddScoped <IContentHandler, FullTextAspectContentHandler>();

            services.AddTagHelpers <ContentLinkTagHelper>();
            services.AddTagHelpers <ContentItemTagHelper>();
            services.Configure <AutorouteOptions>(options =>
            {
                if (options.GlobalRouteValues.Count == 0)
                {
                    options.GlobalRouteValues = new RouteValueDictionary
                    {
                        { "Area", "OrchardCore.Contents" },
                        { "Controller", "Item" },
                        { "Action", "Display" }
                    };

                    options.ContentItemIdKey          = "contentItemId";
                    options.ContainedContentItemIdKey = "containedContentItemId";
                    options.JsonPathKey = "jsonPath";
                }
            });

            services.AddScoped <IContentsAdminListQueryService, DefaultContentsAdminListQueryService>();

            services.AddScoped <IDisplayDriver <ContentOptionsViewModel>, ContentOptionsDisplayDriver>();

            services.AddScoped(typeof(IContentItemRecursionHelper <>), typeof(ContentItemRecursionHelper <>));

            services.AddSingleton <IContentsAdminListFilterParser>(sp =>
            {
                var filterProviders = sp.GetServices <IContentsAdminListFilterProvider>();
                var builder         = new QueryEngineBuilder <ContentItem>();
                foreach (var provider in filterProviders)
                {
                    provider.Build(builder);
                }

                var parser = builder.Build();

                return(new DefaultContentsAdminListFilterParser(parser));
            });

            services.AddTransient <IContentsAdminListFilterProvider, DefaultContentsAdminListFilterProvider>();
        }