Пример #1
0
        // 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");

            BlogManagementBootstrapper.Configure(services, connectionString);
            CommentManagementBootstrapper.Configure(services, connectionString);
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();
            services.AddControllers();
        }
Пример #2
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("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();
        }
Пример #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();
        }
Пример #4
0
        // 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");
            });
        }
Пример #5
0
        // 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("NavidGhavami_PersonalWebsite");



            PersonalInformationBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            ProjectBootstrapper.Configure(services, connectionString);
            ServiceBootstrapper.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.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("PersonalInformation",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

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

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

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

            services.AddRazorPages()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Administration", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Accounts", "Account");
                options.Conventions.AuthorizeAreaFolder("Administration", "/PersonalInformation", "PersonalInformation");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Projects", "Projects");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Services", "Services");
            });
        }