예제 #1
0
 public ParticipateEventController(INotificationService notificationService, HeyImInConfiguration configuration, GetDatabaseContext getDatabaseContext, ILogger <ParticipateEventController> logger, ILoggerFactory loggerFactory)
 {
     _notificationService          = notificationService;
     _maxShownAppointmentsPerEvent = configuration.MaxAmountOfAppointmentsPerDetailPage;
     _getDatabaseContext           = getDatabaseContext;
     _logger      = logger;
     _auditLogger = loggerFactory.CreateAuditLogger();
 }
예제 #2
0
 public SessionService(HeyImInConfiguration configuration, GetDatabaseContext getDatabaseContext, ILogger <SessionService> logger)
 {
     _inactiveSessionTimeout         = configuration.TimeSpans.InactiveSessionTimeout;
     _unusedSessionExpirationTimeout = configuration.TimeSpans.UnusedSessionExpirationTimeout;
     _updateValidUntilTimeSpan       = configuration.TimeSpans.UpdateValidUntilTimeSpan;
     _getDatabaseContext             = getDatabaseContext;
     _logger = logger;
 }
예제 #3
0
        // ReSharper disable once UnusedMember.Global => This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add ASP.NET services
            string connectionString = _configuration.GetConnectionString("HeyImIn");

            services.AddDbContextPool <HeyImInDatabaseContext>(options => options.UseSqlServer(connectionString));
            services.AddResponseCompression();

            // Add global filters / attributes
            services
            .AddMvc(options => { options.Filters.Add(new LogActionAttribute()); })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(options =>
            {
                // Frontend expects property names to be camelCase and vice versa
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
#if DEBUG
                // In debug pretty print the JSON
                options.SerializerSettings.Formatting = Formatting.Indented;
#endif
                options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                // Convert all times to UTC
                options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                options.SerializerSettings.DateParseHandling    = DateParseHandling.DateTime;
                options.SerializerSettings.DateFormatHandling   = DateFormatHandling.IsoDateFormat;
            });

            // Register all services as their matching interface
            // E.g. IMyService <-> MyService
            services.Scan(scan => scan
                          .FromAssembliesOf(
                              typeof(HomeController),           // WebApplication
                              typeof(IDatabaseContext),         // Database
                              typeof(INotificationService),     // MailNotifier
                              typeof(IAuthenticationService)    // Authentication
                              )
                          .AddClasses()
                          .AsMatchingInterface()
                          .WithTransientLifetime());

            // Custom types with sensitive / global configuration
            var sendGridApiKey = _configuration.GetValue <string>("SENDGRID_API_KEY");

            // Other configuration values
            var configuration = new HeyImInConfiguration();
            _configuration.Bind("HeyImInConfiguration", configuration);

            // Register custom types
            services
            .AddSingleton(c => configuration)
            .AddSingleton <Microsoft.Extensions.Hosting.IHostedService, CronBackgroundService>()
            .AddScoped <IDatabaseContext, HeyImInDatabaseContext>()                    // Redirect interface to class
            .AddTransient <ISendGridClient>(c => new SendGridClient(sendGridApiKey))
            .AddTransient <ICronService, CronSendReminderAndSummaryService>()
            .AddTransient <ICronService, CronSendMissedChatMessagesService>()
            .AddTransient <GetDatabaseContext>(c => c.GetRequiredService <IDatabaseContext>);
        }
예제 #4
0
        public void SameWorkFactorDoesNotNeedRehash()
        {
            var    config           = new HeyImInConfiguration();
            var    passwordService  = new PasswordService(config);
            var    passwordService2 = new PasswordService(config);
            string hash             = passwordService.HashPassword(InputPassword);
            bool   needsRehash      = passwordService2.NeedsRehash(hash);

            Assert.False(needsRehash);
        }
예제 #5
0
        public NotificationService(IMailSender mailSender, ISessionService sessionService, HeyImInConfiguration configuration, ILogger <NotificationService> logger)
        {
            _mailSender     = mailSender;
            _sessionService = sessionService;
            _logger         = logger;

            _baseWebUrl = configuration.FrontendBaseUrl;

            try
            {
                _mailTimeZone = TimeZoneInfo.FindSystemTimeZoneById(configuration.MailTimeZoneName);
            }
            catch (Exception e)
            {
                _logger.LogError("{0}(): Configured time zone '{1}' was not valid, error={2}", nameof(NotificationService), configuration.MailTimeZoneName, e);

                _mailTimeZone = TimeZoneInfo.Utc;
            }
        }
예제 #6
0
 public ResetPasswordController(IPasswordService passwordService, INotificationService notificationService, HeyImInConfiguration configuration, GetDatabaseContext getDatabaseContext, ILogger <ResetPasswordController> logger)
 {
     _passwordService         = passwordService;
     _notificationService     = notificationService;
     _resetTokenValidTimeSpan = configuration.TimeSpans.PasswordResetTimeout;
     _getDatabaseContext      = getDatabaseContext;
     _logger = logger;
 }
예제 #7
0
 public PasswordService(HeyImInConfiguration configuration)
 {
     _workFactor = configuration.PasswordHashWorkFactor;
 }
예제 #8
0
 public CronBackgroundService(IServiceScopeFactory serviceScopeFactory, HeyImInConfiguration configuration, ILogger <CronBackgroundService> logger)
 {
     _serviceScopeFactory = serviceScopeFactory;
     _cronHandlerTimeSpan = configuration.TimeSpans.CronHandlerInterval;
     _logger = logger;
 }
 public CronSendMissedChatMessagesService(INotificationService notificationService, HeyImInConfiguration configuration, IDatabaseContext context)
 {
     _notificationService = notificationService;
     _minimumChatMessageNotificationTimeSpan = configuration.TimeSpans.MinimumChatMessageNotificationTimeSpan;
     _context = context;
 }
예제 #10
0
        // ReSharper disable once UnusedMember.Global => This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add ASP.NET services
            string connectionString = _configuration.GetConnectionString("HeyImIn");

            services.AddDbContextPool <HeyImInDatabaseContext>(options => options.UseSqlServer(connectionString));
            services.AddResponseCompression();

            // Add global filters / attributes
            services
            .AddMvc(options => { options.Filters.Add(new LogActionAttribute()); })
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddJsonOptions(options =>
            {
                // Frontend expects property names to be camelCase and vice versa
#if DEBUG
                // In debug pretty print the JSON
                options.JsonSerializerOptions.WriteIndented = true;
#endif
                options.JsonSerializerOptions.IgnoreNullValues     = true;
                options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
            });

            services.AddApiVersioning(
                options =>
            {
                options.ReportApiVersions = false;
                options.ErrorResponses    = new ApiVersionErrorResponseProvider();
                options.ApiVersionReader  = new QueryStringApiVersionReader("api-version");
                options.AssumeDefaultVersionWhenUnspecified = false;
            });

            // Register all services as their matching interface
            // E.g. IMyService <-> MyService
            services.Scan(scan => scan
                          .FromAssembliesOf(
                              typeof(HomeController),           // WebApplication
                              typeof(IDatabaseContext),         // Database
                              typeof(INotificationService),     // MailNotifier
                              typeof(IAuthenticationService)    // Authentication
                              )
                          .AddClasses()
                          .AsMatchingInterface()
                          .WithTransientLifetime());

            // Custom types with sensitive / global configuration
            var sendGridApiKey = _configuration.GetValue <string>("SENDGRID_API_KEY");

            // Other configuration values
            var configuration = new HeyImInConfiguration();
            _configuration.Bind("HeyImInConfiguration", configuration);

            // Register custom types
            services
            .AddSingleton(c => configuration)
            .AddSingleton <IHostedService, CronBackgroundService>()
            .AddScoped <IDatabaseContext, HeyImInDatabaseContext>()                    // Redirect interface to class
            .AddTransient <ISendGridClient>(c => new SendGridClient(sendGridApiKey))
            .AddTransient <ICronService, CronSendReminderAndSummaryService>()
            .AddTransient <ICronService, CronSendMissedChatMessagesService>()
            .AddTransient <GetDatabaseContext>(c => c.GetRequiredService <IDatabaseContext>);
        }