예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountService"/> class.
 /// </summary>
 /// <param name="staticConfig">The static configuration.</param>
 /// <param name="userData">The user data.</param>
 /// <param name="userTokenData">The user token data.</param>
 /// <param name="adminLogService">The admin log service.</param>
 public AccountService(IStaticConfig staticConfig, IUserData userData, IUserTokenData userTokenData, IAdminLogService adminLogService)
 {
     _staticConfig    = staticConfig;
     _userData        = userData;
     _userTokenData   = userTokenData;
     _adminLogService = adminLogService;
 }
예제 #2
0
 public BlogController(ILogger <BlogController> logger, IHttpClientFactory httpClientFactory, IStaticConfig staticConfig)
 {
     _logger            = logger;
     this._staticConfig = staticConfig;
     // _httpClient = httpClientFactory.CreateClient("name");//工厂创建   services.AddHttpClient("",options=>options.BaseAddress = new Uri(Configuration["StaticConfigs:BlogApiUrl"]));
     _httpClient = httpClientFactory.CreateClient();
 }
예제 #3
0
        public SecurityService(IOptions <JwtAuthentication> jwtAuthentication, IStaticConfig staticConfig)
        {
            _jwtAuthentication = jwtAuthentication?.Value ?? throw new ArgumentNullException(nameof(jwtAuthentication));
            _staticConfig      = staticConfig;

            ValidIssuer   = _jwtAuthentication.ValidIssuer;
            ValidAudience = _jwtAuthentication.ValidAudience;
        }
예제 #4
0
        public ConfigService(IConfigData config, IDynamicConfig dynamicConfig, IStaticConfig staticConfig)
        {
            _configData   = config;
            DynamicConfig = dynamicConfig;
            StaticConfig  = staticConfig;

            DynamicConfig.PropertyChanged += _dynamicConfig_PropertyChanged;
        }
예제 #5
0
 /// <summary>Initializes a new instance of the <see cref="AuthController" /> class.</summary>
 /// <param name="logger">The logger.</param>
 /// <param name="jwtAuthentication">The JWT authentication.</param>
 /// <param name="accountService">The account service.</param>
 /// <param name="staticConfig">The static configuration.</param>
 /// <param name="securityService">The security service.</param>
 /// <exception cref="ArgumentNullException">jwtAuthentication</exception>
 public AuthController(ILogger <AuthController> logger,
                       IOptions <JwtAuthentication> jwtAuthentication,
                       IAccountService accountService,
                       IStaticConfig staticConfig,
                       ISecurityService securityService)
 {
     _logger            = logger;
     _jwtAuthentication = jwtAuthentication?.Value ?? throw new ArgumentNullException(nameof(jwtAuthentication));
     _accountService    = accountService;
     _staticConfig      = staticConfig;
     _securityService   = securityService;
 }
예제 #6
0
 /// <summary>Initializes a new instance of the <see cref="AccountController" /> class.</summary>
 /// <param name="logger">The logger.</param>
 /// <param name="accountService">The account service.</param>
 /// <param name="staticConfig">The static configuration.</param>
 /// <param name="securityService">The security service.</param>
 /// <param name="fileUploadService">The file upload service.</param>
 /// <param name="dynamicConfig">The dynamic configuration.</param>
 public AccountController(ILogger <AccountController> logger,
                          IAccountService accountService,
                          IStaticConfig staticConfig,
                          ISecurityService securityService,
                          IFileUploadService fileUploadService,
                          IDynamicConfig dynamicConfig)
 {
     _logger            = logger;
     _accountService    = accountService;
     _staticConfig      = staticConfig;
     _securityService   = securityService;
     _fileUploadService = fileUploadService;
     _dynamicConfig     = dynamicConfig;
 }
예제 #7
0
 public LoremIpsumDatabaseService(IStaticConfig staticConfig)
 {
     _staticConfig = staticConfig;
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserTokenData"/> class.
 /// </summary>
 /// <param name="staticConfig">The static configuration.</param>
 public UserTokenData(IStaticConfig staticConfig) : base(staticConfig)
 {
 }
 public MySQLDatabaseService(IStaticConfig staticConfig)
 {
     _staticConfig = staticConfig;
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogData"/> class.
 /// </summary>
 /// <param name="staticConfig">The static configuration.</param>
 public LogData(IStaticConfig staticConfig) : base(staticConfig)
 {
 }
예제 #11
0
 public ImageTransformer(ILogger <ImageTransformer> logger, IStaticConfig staticConfig)
 {
     _logger       = logger;
     _staticConfig = staticConfig;
 }
 public HelloWorldDatabaseService(IStaticConfig staticConfig)
 {
     _staticConfig = staticConfig;
 }
예제 #13
0
 /// <summary>Initializes a new instance of the <see cref="PhotosController" /> class.</summary>
 /// <param name="logger">The logger.</param>
 /// <param name="photoSevice">The photo sevice.</param>
 /// <param name="staticConfig">The static configuration.</param>
 public PhotosController(ILogger <PhotosController> logger, IPhotoService photoSevice, IStaticConfig staticConfig)
 {
     _logger       = logger;
     _photoSevice  = photoSevice;
     _staticConfig = staticConfig;
 }
예제 #14
0
 public AdminLogService(ILogData logData, IStaticConfig staticConfig)
 {
     _logData = logData;
     _staticConfig = staticConfig;
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataBase"/> class.
 /// </summary>
 /// <param name="staticConfig">The static configuration.</param>
 public DataBase(IStaticConfig staticConfig)
 {
     _staticConfig = staticConfig;
     SimpleCRUD.SetDialect(SimpleCRUD.Dialect.SQLite);
 }
예제 #16
0
 /// <summary>Initializes a new instance of the <see cref="UsersController" /> class.</summary>
 /// <param name="logger">The logger.</param>
 /// <param name="accountService">The account service.</param>
 /// <param name="staticConfig">The static configuration.</param>
 public UsersController(ILogger <UsersController> logger, IAccountService accountService, IStaticConfig staticConfig)
 {
     _logger         = logger;
     _accountService = accountService;
     _staticConfig   = staticConfig;
 }
예제 #17
0
        /// <summary>
        /// Middleware entry point.
        /// </summary>
        /// <param name="httpContext">The request.</param>
        /// <param name="dynamicConfig">The dynamic configuration.</param>
        /// <param name="staticConfig">The static configuration.</param>
        /// <returns>A void task.</returns>
        public async Task InvokeAsync(HttpContext httpContext, IDynamicConfig dynamicConfig, IStaticConfig staticConfig)
        {
            var request = httpContext.Request;

            if (request.Method.Equals("GET", StringComparison.InvariantCultureIgnoreCase) &&
                httpContext.Request.Path.Value.StartsWith(Constants.CacheRoute, StringComparison.InvariantCultureIgnoreCase))
            {
                var folderAndFileInfo = httpContext.Request.Path.Value.Substring(Constants.CacheRoute.Length).Trim('/').Split('/');
                var size = httpContext.Request.Query.ContainsKey("type") ? httpContext.Request.Query["type"].ToString().ToLower() : "thumb";

                switch (size)
                {
                case "thumb":
                case "thumbnail":
                    size = "thumb";
                    break;

                case "small":
                case "sm":
                    size = "small";
                    break;

                case "full":
                case "large":
                case "lg":
                    size = "full";
                    break;
                }

                httpContext.Response.Headers.Add("Cache-Control", "Private");
                httpContext.Response.Headers.Add("Expires", DateTime.UtcNow.AddDays(staticConfig.PhotoExpirationDays).ToString("u"));

                var folder        = folderAndFileInfo[0];
                var fileInfo      = folderAndFileInfo[1].Decrypt(staticConfig.ImagePasscode);
                var fileInfoParts = fileInfo.Split('|');
                var file          = fileInfoParts[0];
                var expiration    = DateTime.Parse(fileInfoParts[1]);

                if (expiration < DateTime.UtcNow.ToStartOfDay())
                {
                    httpContext.Response.StatusCode = 400;
                    return;
                }

                var cachePath = Path.Combine(dynamicConfig.CacheFolder.TrimEnd('/', '\\'), folder, size, file);
                await httpContext.Response.SendFileAsync(cachePath);
            }
            else
            {
                await _next(httpContext);
            }
        }