// 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("DigitalStoreDb");

            ShopManagementBoostrapper.Configur(services, connectionString);
            DiscountManagementBootstrapper.Configure(services, connectionString);
            InventoryManagementBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IProductQuery, ProductQuery>();
            services.AddRazorPages();
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages().AddMvcOptions(x => x.Filters.Add <SecurityPageFilter>()).AddRazorRuntimeCompilation().AddRazorPagesOptions(x =>
            {
                x.Conventions.AuthorizeAreaFolder("Admin", "/", "AdminArea");
                x.Conventions.AuthorizeAreaFolder("Admin", "/Discount", "Discounts");
                x.Conventions.AuthorizeAreaFolder("Admin", "/Accounts", "Accounts");
            });
            services.AddHttpContextAccessor();

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.Strict;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
            {
                options.LoginPath        = new PathString("/Account");
                options.LogoutPath       = new PathString("/Account");
                options.AccessDeniedPath = new PathString("/AccessDenied");
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea", builder => builder.RequireRole(new List <string> {
                    Roles.Admin, Roles.Operator
                }));
                options.AddPolicy("Discounts", builder => builder.RequireRole(new List <string> {
                    Roles.Admin
                }));
                options.AddPolicy("Accounts", builder => builder.RequireRole(new List <string> {
                    Roles.Admin
                }));
            });

            var connectionString = Configuration.GetConnectionString("ShopConnectionString");

            ShopManagementBootstraper.Configure(services, connectionString);
            DiscountManagementBootstrapper.Configure(services, connectionString);
            InventoryManagementBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);

            services.AddTransient <IFileUploader, FileUploader>();
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddSingleton <IAuthHelper, AuthHelper>();
        }
Example #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();
            var connectionString = Configuration.GetConnectionString("LampshadeDb");

            ShopManagementBootstrapper.Configure(services, connectionString);
            DiscountManagementBootstrapper.Configure(services, connectionString);
            InventoryManagementBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            CommentManagementBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);

            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            services.AddTransient <IZarinPalFactory, ZarinPalFactory>();
            services.AddTransient <ISmsService, SmsService>();
            services.AddTransient <IEmailService, EmailService>();

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.Lax;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.ContentUploader
                }));

                options.AddPolicy("Shop",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Discount",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Account",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));
            });

            services.AddCors(options => options.AddPolicy("MyPolicy", builder =>
                                                          builder
                                                          .WithOrigins("https://localhost:5002")
                                                          .AllowAnyHeader()
                                                          .AllowAnyMethod()));

            services.AddRazorPages()
            .AddMvcOptions(options => options.Filters.Add <SecurityPageFilter>())
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Administration", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Shop", "Shop");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Discounts", "Discount");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Accounts", "Account");
            })
            .AddApplicationPart(typeof(ProductController).Assembly)
            .AddApplicationPart(typeof(InventoryController).Assembly)
            .AddNewtonsoftJson();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            var connectionString = Configuration.GetConnectionString("LampshadeDb");

            ShopMangementBootstrapper.Configure(services, connectionString);
            DiscountManagementBootStrapper.Configure(services, connectionString);
            InventoryManagementBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            CommentManagementBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);


            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));


            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            services.AddTransient <IZarinPalFactory, ZarinPalFactory>();



            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.Lax;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });


            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.ContentUploader, Roles.AdminAssistant
                }));

                options.AddPolicy("Shop",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));

                options.AddPolicy("Discount",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));

                options.AddPolicy("Account",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));

                options.AddPolicy("Inventory",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.AdminAssistant
                }));
            });


            services.AddRazorPages()
            .AddMvcOptions(options => options.Filters.Add <SecurityPageFilter>())
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Shop", "Shop");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Discount", "Discount");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Accounts", "Account");
                options.Conventions.AuthorizeAreaFolder("Adminstration", "/Inventory", "Inventory");
            });
        }