コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaFileSystem"/> class.
 /// </summary>
 public MediaFileSystem(IFileSystem innerFileSystem, IContentSection contentConfig, IMediaPathScheme mediaPathScheme, ILogger logger)
     : base(innerFileSystem)
 {
     _contentConfig   = contentConfig;
     _mediaPathScheme = mediaPathScheme;
     _logger          = logger;
 }
コード例 #2
0
        /// <summary>
        /// Configure Default Identity User Manager for Umbraco
        /// </summary>
        /// <param name="app"></param>
        /// <param name="services"></param>
        /// <param name="contentSettings"></param>
        /// <param name="globalSettings"></param>
        /// <param name="userMembershipProvider"></param>
        public static void ConfigureUserManagerForUmbracoBackOffice(this IAppBuilder app,
                                                                    ServiceContext services,
                                                                    IContentSection contentSettings,
                                                                    IGlobalSettings globalSettings,
                                                                    MembershipProviderBase userMembershipProvider)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (userMembershipProvider == null)
            {
                throw new ArgumentNullException(nameof(userMembershipProvider));
            }

            //Configure Umbraco user manager to be created per request
            app.CreatePerOwinContext <BackOfficeUserManager>(
                (options, owinContext) => BackOfficeUserManager.Create(
                    options,
                    services.UserService,
                    services.MemberTypeService,
                    services.EntityService,
                    services.ExternalLoginService,
                    userMembershipProvider,
                    contentSettings,
                    globalSettings));

            app.SetBackOfficeUserManagerType <BackOfficeUserManager, BackOfficeIdentityUser>();

            //Create a sign in manager per request
            app.CreatePerOwinContext <BackOfficeSignInManager>((options, context) => BackOfficeSignInManager.Create(options, context, globalSettings, app.CreateLogger <BackOfficeSignInManager>()));
        }
コード例 #3
0
 public FileUploadPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSection)
     : base(logger)
 {
     _mediaFileSystem          = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem));
     _contentSection           = contentSection;
     _uploadAutoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, contentSection);
 }
コード例 #4
0
        /// <summary>
        /// Configure a custom UserStore with the Identity User Manager for Umbraco
        /// </summary>
        /// <param name="app"></param>
        /// <param name="runtimeState"></param>
        /// <param name="globalSettings"></param>
        /// <param name="userMembershipProvider"></param>
        /// <param name="customUserStore"></param>
        /// <param name="contentSettings"></param>
        public static void ConfigureUserManagerForUmbracoBackOffice(this IAppBuilder app,
                                                                    IRuntimeState runtimeState,
                                                                    IContentSection contentSettings,
                                                                    IGlobalSettings globalSettings,
                                                                    MembershipProviderBase userMembershipProvider,
                                                                    BackOfficeUserStore customUserStore)
        {
            if (runtimeState == null)
            {
                throw new ArgumentNullException(nameof(runtimeState));
            }
            if (userMembershipProvider == null)
            {
                throw new ArgumentNullException(nameof(userMembershipProvider));
            }
            if (customUserStore == null)
            {
                throw new ArgumentNullException(nameof(customUserStore));
            }

            //Configure Umbraco user manager to be created per request
            app.CreatePerOwinContext <BackOfficeUserManager>(
                (options, owinContext) => BackOfficeUserManager.Create(
                    options,
                    customUserStore,
                    userMembershipProvider,
                    contentSettings));

            app.SetBackOfficeUserManagerType <BackOfficeUserManager, BackOfficeIdentityUser>();

            //Create a sign in manager per request
            app.CreatePerOwinContext <BackOfficeSignInManager>((options, context) => BackOfficeSignInManager.Create(options, context, globalSettings, app.CreateLogger(typeof(BackOfficeSignInManager).FullName)));
        }
コード例 #5
0
        private void SavingMedia(IMediaService sender, SaveEventArgs <IMedia> e)
        {
            MediaFileSystem      mediaFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>();
            IContentSection      contentSection  = UmbracoConfig.For.UmbracoSettings().Content;
            IEnumerable <string> supportedTypes  = contentSection.ImageFileTypes.ToList();

            foreach (var entity in e.SavedEntities)
            {
                if (!entity.HasProperty("umbracoFile"))
                {
                    continue;
                }

                var path      = entity.GetValue <string>("umbracoFile");
                var extension = Path.GetExtension(path)?.Substring(1);

                if (!supportedTypes.InvariantContains(extension))
                {
                    continue;
                }

                var fullPath = mediaFileSystem.GetFullPath(path);
                using (ImageFactory imageFactory = new ImageFactory(true))
                {
                    ResizeLayer layer = new ResizeLayer(new Size(1920, 0), ResizeMode.Max)
                    {
                        Upscale = false
                    };

                    imageFactory.Load(fullPath)
                    .Resize(layer)
                    .Save(fullPath);
                }
            }
        }
コード例 #6
0
 public MediaFileSystem(IFileSystem wrapped, IContentSection contentConfig, ILogger logger)
     : base(wrapped)
 {
     _logger                   = logger;
     _contentConfig            = contentConfig;
     _uploadAutoFillProperties = new UploadAutoFillProperties(this, logger, contentConfig);
 }
コード例 #7
0
        /// <summary>
        /// Creates a BackOfficeUserManager instance with all default options and the default BackOfficeUserManager
        /// </summary>
        /// <param name="options"></param>
        /// <param name="userService"></param>
        /// <param name="entityService"></param>
        /// <param name="externalLoginService"></param>
        /// <param name="membershipProvider"></param>
        /// <param name="contentSectionConfig"></param>
        /// <returns></returns>
        public static BackOfficeUserManager Create(
            IdentityFactoryOptions <BackOfficeUserManager> options,
            IUserService userService,
            IEntityService entityService,
            IExternalLoginService externalLoginService,
            MembershipProviderBase membershipProvider,
            IContentSection contentSectionConfig)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (userService == null)
            {
                throw new ArgumentNullException("userService");
            }
            if (externalLoginService == null)
            {
                throw new ArgumentNullException("externalLoginService");
            }

            var manager = new BackOfficeUserManager(
                new BackOfficeUserStore(userService, entityService, externalLoginService, membershipProvider));

            manager.InitUserManager(manager, membershipProvider, contentSectionConfig, options);
            return(manager);
        }
コード例 #8
0
 public HttpsCheck(ILocalizedTextService textService, IRuntimeState runtime, IGlobalSettings globalSettings, IContentSection contentSection)
 {
     _textService    = textService;
     _runtime        = runtime;
     _globalSettings = globalSettings;
     _contentSection = contentSection;
 }
コード例 #9
0
 /// <summary>
 /// Gets the urls of a media item.
 /// </summary>
 public static string[] GetUrls(this IMedia media, IContentSection contentSection, ILogger logger)
 {
     return(contentSection.ImageAutoFillProperties
            .Select(field => media.GetUrl(field.Alias, logger))
            .Where(link => string.IsNullOrWhiteSpace(link) == false)
            .ToArray());
 }
コード例 #10
0
 public ImagePreprocessingComponent(IMediaFileSystem mediaFileSystem, IContentSection contentSection,
                                    IMediaService mediaService, IMediaTypeService mediaTypeService, IContentTypeBaseServiceProvider contentTypeBaseService)
 {
     _mediaFileSystem        = mediaFileSystem;
     _contentSection         = contentSection;
     _mediaService           = mediaService;
     _mediaTypeService       = mediaTypeService;
     _contentTypeBaseService = contentTypeBaseService;
 }
コード例 #11
0
 public ScriptRepository(IUnitOfWork work, IFileSystem fileSystem, IContentSection contentConfig)
     : base(work, fileSystem)
 {
     if (contentConfig == null)
     {
         throw new ArgumentNullException("contentConfig");
     }
     _contentConfig = contentConfig;
 }
コード例 #12
0
 public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService)
 {
     _plogger = plogger ?? throw new ArgumentNullException(nameof(plogger));
     _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
     _contentSection         = contentSection ?? throw new ArgumentNullException(nameof(contentSection));
     _textService            = textService;
     _appCaches    = appCaches ?? throw new ArgumentNullException(nameof(appCaches));
     _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService));
 }
コード例 #13
0
 /// <summary>
 /// Initializes the user manager with the correct options
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="membershipProvider"></param>
 /// <param name="contentSectionConfig"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 protected void InitUserManager(
     BackOfficeUserManager manager,
     MembershipProviderBase membershipProvider,
     IContentSection contentSectionConfig,
     IdentityFactoryOptions <BackOfficeUserManager> options)
 {
     //NOTE: This method is mostly here for backwards compat
     base.InitUserManager(manager, membershipProvider, options.DataProtectionProvider, contentSectionConfig);
 }
コード例 #14
0
        /// <summary>
        /// Creates a BackOfficeUserManager instance with all default options and a custom BackOfficeUserManager instance
        /// </summary>
        /// <param name="options"></param>
        /// <param name="customUserStore"></param>
        /// <param name="membershipProvider"></param>
        /// <param name="contentSectionConfig"></param>
        /// <returns></returns>
        public static BackOfficeUserManager Create(
            IdentityFactoryOptions <BackOfficeUserManager> options,
            BackOfficeUserStore customUserStore,
            MembershipProviderBase membershipProvider,
            IContentSection contentSectionConfig)
        {
            var manager = new BackOfficeUserManager(customUserStore, options, membershipProvider, contentSectionConfig);

            return(manager);
        }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageCropperPropertyEditor"/> class.
        /// </summary>
        public ImageCropperPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSettings, IDataTypeService dataTypeService)
            : base(logger)
        {
            _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem));
            _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings));
            _dataTypeService = dataTypeService;

            // TODO: inject?
            _autoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, _contentSettings);
        }
コード例 #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="umbracoContextAccessor"></param>
 /// <param name="notificationService"></param>
 /// <param name="userService"></param>
 /// <param name="textService"></param>
 /// <param name="globalSettings"></param>
 /// <param name="contentConfig"></param>
 /// <param name="logger"></param>
 public Notifier(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, IContentSection contentConfig, ILogger logger)
 {
     _umbracoContextAccessor = umbracoContextAccessor;
     _runtimeState           = runtimeState;
     _notificationService    = notificationService;
     _userService            = userService;
     _textService            = textService;
     _globalSettings         = globalSettings;
     _contentConfig          = contentConfig;
     _logger = logger;
 }
コード例 #17
0
 public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService,
                            ILogger logger, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, IContentSection contentSection)
 {
     _notificationsRepository = notificationsRepository;
     _globalSettings          = globalSettings;
     _contentSection          = contentSection;
     _uowProvider             = provider ?? throw new ArgumentNullException(nameof(provider));
     _userService             = userService ?? throw new ArgumentNullException(nameof(userService));
     _contentService          = contentService ?? throw new ArgumentNullException(nameof(contentService));
     _localizationService     = localizationService;
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
コード例 #18
0
 public BackOfficeUserManager(
     IUserStore <BackOfficeIdentityUser, int> store,
     IdentityFactoryOptions <BackOfficeUserManager> options,
     MembershipProviderBase membershipProvider,
     IContentSection contentSectionConfig)
     : base(store)
 {
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     InitUserManager(this, membershipProvider, contentSectionConfig, options);
 }
コード例 #19
0
 /// <summary>
 /// Gets a value indicating whether the file extension corresponds to an image.
 /// </summary>
 /// <param name="extension">The file extension.</param>
 /// <param name="contentConfig"></param>
 /// <returns>A value indicating whether the file extension corresponds to an image.</returns>
 public static bool IsImageFile(this IContentSection contentConfig, string extension)
 {
     if (contentConfig == null)
     {
         throw new ArgumentNullException(nameof(contentConfig));
     }
     if (extension == null)
     {
         return(false);
     }
     extension = extension.TrimStart('.');
     return(contentConfig.ImageFileTypes.InvariantContains(extension));
 }
コード例 #20
0
 /// <summary>
 /// All dependencies
 /// </summary>
 /// <param name="umbracoContext"></param>
 /// <param name="umbracoHelper"></param>
 /// <param name="searchProvider"></param>
 /// <param name="contentSectionConfig"></param>
 public MediaController(
     UmbracoContext umbracoContext,
     UmbracoHelper umbracoHelper,
     BaseSearchProvider searchProvider,
     IContentSection contentSectionConfig)
     : base(umbracoContext, umbracoHelper)
 {
     if (searchProvider == null)
     {
         throw new ArgumentNullException("searchProvider");
     }
     _searchProvider       = searchProvider;
     _contentSectionConfig = contentSectionConfig;
 }
コード例 #21
0
        void MediaService_Saving(IMediaService mediaService, SaveEventArgs <IMedia> args)
        {
            // Don't allow upload in root
            if (args.SavedEntities.Any() && args.SavedEntities.First().ParentId == -1 && args.SavedEntities.First().HasProperty("umbracoFile"))
            {
                LogHelper.Warn(this.GetType(), "Files are not allowed to be uploaded in the root folder");
                args.Cancel = true;
                return;
            }


            MediaFileSystem      mediaFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>();
            IContentSection      contentSection  = UmbracoConfig.For.UmbracoSettings().Content;
            IEnumerable <string> supportedTypes  = contentSection.ImageFileTypes.ToList();

            foreach (IMedia media in args.SavedEntities)
            {
                if (media.HasProperty("umbracoFile"))
                {
                    // Make sure it's an image.
                    string path          = media.GetValue <string>("umbracoFile");
                    var    fullExtension = Path.GetExtension(path);
                    if (fullExtension != null)
                    {
                        string extension = fullExtension.Substring(1);
                        if (supportedTypes.InvariantContains(extension))
                        {
                            // Get maxwidth from parent folder
                            var maxWidth = GetMaxWidthFromParent(DefaultMaxWidth, media);

                            if (maxWidth < media.GetValue <int>("umbracoWidth"))
                            {
                                // Resize the image to maxWidth:px wide, height is driven by the aspect ratio of the image.
                                string fullPath = mediaFileSystem.GetFullPath(path);
                                using (ImageFactory imageFactory = new ImageFactory(true))
                                {
                                    ResizeLayer layer = new ResizeLayer(new Size(maxWidth, 0), resizeMode: ResizeMode.Max, anchorPosition: AnchorPosition.Center, upscale: false);
                                    imageFactory.Load(fullPath).Resize(layer).Save(fullPath);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #22
0
        /// <summary>
        /// Creates a BackOfficeUserManager instance with all default options and the default BackOfficeUserManager
        /// </summary>
        /// <param name="options"></param>
        /// <param name="userService"></param>
        /// <param name="externalLoginService"></param>
        /// <param name="membershipProvider"></param>
        /// <returns></returns>
        public static FortressBackOfficeUserManager Create(
            IdentityFactoryOptions <FortressBackOfficeUserManager> options,
            IUserService userService,
            IEntityService entitiyService,
            IExternalLoginService externalLoginService,
            MembershipProviderBase membershipProvider,
            IContentSection content)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (userService == null)
            {
                throw new ArgumentNullException("userService");
            }
            if (externalLoginService == null)
            {
                throw new ArgumentNullException("externalLoginService");
            }

            var manager = new FortressBackOfficeUserManager(new FortressBackOfficeUserStore(userService, entitiyService, externalLoginService, membershipProvider));

            //manager.InitUserManager(manager, membershipProvider, contentSectionConfig, options as BackOfficeUserManager);
            manager.InitUserManager(manager, membershipProvider, options.DataProtectionProvider, content);


            //Here you can specify the 2FA providers that you want to implement,
            //in this demo we are using the custom AcceptAnyCodeProvider - which literally accepts any code - do not actually use this!

            var dataProtectionProvider = options.DataProtectionProvider;

            manager.RegisterTwoFactorProvider("GoogleAuthenticator", new GoogleAuthenticatorProvider(dataProtectionProvider.Create("GoogleAuthenticator")));

            return(manager);
        }
コード例 #23
0
 protected VersionableRepositoryBase(IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax, IContentSection contentSection)
     : base(work, cache, logger, sqlSyntax)
 {
     _contentSection = contentSection;
 }
コード例 #24
0
 public AvailablePropertyEditorsResolver(IContentSection contentSection)
 {
     _contentSection = contentSection;
 }
コード例 #25
0
ファイル: Script.cs プロジェクト: phaniarveti/Experiments
 public Script(string path, IContentSection contentConfig)
     : base(path)
 {
     _contentConfig = contentConfig;
     base.Path = path;
 }
コード例 #26
0
 public ScriptRepository(IFileSystems fileSystems, IContentSection contentConfig)
     : base(fileSystems.ScriptsFileSystem)
 {
     _contentConfig = contentConfig ?? throw new ArgumentNullException(nameof(contentConfig));
 }
コード例 #27
0
 public MediaRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax, IMediaTypeRepository mediaTypeRepository, ITagRepository tagRepository, IContentSection contentSection)
     : base(work, cache, logger, sqlSyntax, contentSection)
 {
     if (mediaTypeRepository == null)
     {
         throw new ArgumentNullException("mediaTypeRepository");
     }
     if (tagRepository == null)
     {
         throw new ArgumentNullException("tagRepository");
     }
     _mediaTypeRepository      = mediaTypeRepository;
     _tagRepository            = tagRepository;
     _contentXmlRepository     = new ContentXmlRepository <IMedia>(work, CacheHelper.CreateDisabledCacheHelper(), logger, sqlSyntax);
     _contentPreviewRepository = new ContentPreviewRepository <IMedia>(work, CacheHelper.CreateDisabledCacheHelper(), logger, sqlSyntax);
     EnsureUniqueNaming        = contentSection.EnsureUniqueNaming;
 }
コード例 #28
0
 public MediaFileSystem(IFileSystem wrapped, IContentSection contentConfig) : base(wrapped)
 {
     _contentConfig = contentConfig;
 }
コード例 #29
0
 public DefaultContentVersionCleanupPolicy(IContentSection contentSection, IScopeProvider scopeProvider, IDocumentVersionRepository documentVersionRepository)
 {
     _contentSection            = contentSection ?? throw new ArgumentNullException(nameof(contentSection));
     _scopeProvider             = scopeProvider ?? throw new ArgumentNullException(nameof(scopeProvider));
     _documentVersionRepository = documentVersionRepository ?? throw new ArgumentNullException(nameof(documentVersionRepository));
 }
コード例 #30
0
 public ParameterEditorResolver(IServiceProvider serviceProvider, ILogger logger, Func <IEnumerable <Type> > typeListProducerList, ManifestBuilder builder)
     : base(serviceProvider, logger, typeListProducerList, ObjectLifetimeScope.Application)
 {
     _builder        = builder;
     _contentSection = UmbracoConfig.For.UmbracoSettings().Content;
 }
コード例 #31
0
        /// <summary>
        /// Gets the auto-fill configuration for a specified property alias.
        /// </summary>
        /// <param name="contentSection"></param>
        /// <param name="propertyTypeAlias">The property type alias.</param>
        /// <returns>The auto-fill configuration for the specified property alias, or null.</returns>
        public static IImagingAutoFillUploadField GetConfig(this IContentSection contentSection, string propertyTypeAlias)
        {
            var autoFillConfigs = contentSection.ImageAutoFillProperties;

            return(autoFillConfigs?.FirstOrDefault(x => x.Alias == propertyTypeAlias));
        }
コード例 #32
0
 /// <summary>
 /// Determines if file extension is allowed for upload based on (optional) white list and black list
 /// held in settings.
 /// Allow upload if extension is whitelisted OR if there is no whitelist and extension is NOT blacklisted.
 /// </summary>
 public static bool IsFileAllowedForUpload(this IContentSection contentSection, string extension)
 {
     return(contentSection.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)) ||
            (contentSection.AllowedUploadFiles.Any() == false &&
             contentSection.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)) == false));
 }