Exemplo n.º 1
0
 public HomeController(ITraktService traktService, UserManager <IdentityUser> userManager, AppDbContext appDbContext, ToplistConfiguration toplistConfiguration)
 {
     _traktService         = traktService;
     _userManager          = userManager;
     _appDbContext         = appDbContext;
     _toplistConfiguration = toplistConfiguration;
 }
Exemplo n.º 2
0
 public HomeController(ITraktService traktService, ToplistConfiguration toplistConfiguration)
 {
     _traktService         = traktService;
     _toplistConfiguration = toplistConfiguration;
 }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // Config
            var hangfireConfiguration = new HangFireConfiguration();

            Configuration.Bind("Hangfire", hangfireConfiguration);
            services.AddSingleton(hangfireConfiguration);

            var toplistConfiguration = new ToplistConfiguration();

            Configuration.Bind("Toplist", toplistConfiguration);
            services.AddSingleton(toplistConfiguration);

            var traktApiConfiguration = new TraktAPIConfiguration();

            Configuration.Bind("Trakt", traktApiConfiguration);
            services.AddSingleton(traktApiConfiguration);

            // Multi Instance LB
            services.AddDbContext <DataProtectionDbContext>(options =>
                                                            options.UseSqlServer(connectionString)
                                                            );

            services.AddDataProtection()
            .PersistKeysToDbContext <DataProtectionDbContext>()
            .SetApplicationName("Listrr");

            services.AddDistributedSqlServerCache(options =>
            {
                options.ConnectionString = connectionString;
                options.SchemaName       = "dbo";
                options.TableName        = "Cache";
            });


            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(connectionString)
                                                 );

            services.AddDefaultIdentity <IdentityUser>(options =>
            {
                options.User.AllowedUserNameCharacters = null;
            }).AddEntityFrameworkStores <AppDbContext>();

            services.AddHangfire(x =>
                                 x.UseSqlServerStorage(connectionString));

            services.AddAuthentication()
            .AddTrakt(options =>
            {
                options.ClientId                = traktApiConfiguration.ClientId;
                options.ClientSecret            = traktApiConfiguration.ClientSecret;
                options.SaveTokens              = true;
                options.Events.OnCreatingTicket = ctx =>
                {
                    List <AuthenticationToken> tokens = ctx.Properties.GetTokens() as List <AuthenticationToken>;
                    tokens.Add(new AuthenticationToken()
                    {
                        Name  = "TicketCreated",
                        Value = DateTime.Now.ToString()
                    });
                    ctx.Properties.StoreTokens(tokens);
                    return(Task.CompletedTask);
                };
            });

            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.Name     = "Listrr";
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromHours(1);

                options.LoginPath         = "/Identity/Account/Login";
                options.AccessDeniedPath  = "/Identity/Account/AccessDenied";
                options.SlidingExpiration = true;
            });

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddHttpContextAccessor();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });

            services.AddScoped <ITraktListDBRepository, TraktListDBRepository>();
            services.AddScoped <ITraktListAPIRepository, TraktListAPIRepository>();
            services.AddScoped <ITraktService, TraktService>();
        }