// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context, RoleManager <AppRole> roleManager, UserManager <AppUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAuthorization();

            // seeding database if not available default values
            DbSeeder.SeedDb(context, roleManager);
            DbSeeder.SeedUsers(userManager);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, UserManager <IdentityUser> userManager, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else if (env.IsStaging() || env.IsProduction() || env.IsEnvironment("ExternalProduction"))
            {
                app.UseExceptionHandler("/Error");
            }

            DbSeeder.SeedUsers(userManager);

            app.UseAuthentication();

            app.UseStaticFiles();

            app.UseDeveloperExceptionPage();

            app.UseMvcWithDefaultRoute();

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Invalid URL!");
            });
        }
Exemple #3
0
        public override void Seed()
        {
            lock (_lock)
            {
                if (!_databaseInitialized)
                {
                    using (var context = CreateContext())
                    {
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();

                        var userManager = TestHelpers.Identity.CreateUserManager(context);
                        var roleManager = TestHelpers.Identity.CreateRoleManager(context);

                        var seeder = new DbSeeder(context, userManager, roleManager, new NullLogger <DbSeeder>());

                        var membersWithRoles = new Dictionary <int, string>();

                        for (int i = 1; i < 11; i++)
                        {
                            membersWithRoles.Add(i, "Member");
                        }

                        bool seedSuccess = seeder.SeedUsers(membersWithRoles).Result;
                    }

                    _databaseInitialized = true;
                }
            }
        }
Exemple #4
0
        public static void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <TrackilyUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.Use(async(context, next) =>
            {
                await next();
                if (context.Response.StatusCode == 404)
                {
                    context.Request.Path = "/Home/Error/404";
                    await next();
                }
            });

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            DbSeeder.SeedUsers(userManager);
        }
        public async Task <Object> Seed(LoginViewModel model)
        {
            var user = await UserManager.FindByEmailAsync(model.Email);

            if ((user == null || !await UserManager.CheckPasswordAsync(user, model.Password)) && !(model.Email == "*****@*****.**" && model.Password == "thereisnousersyet"))
            {
                // user does not exists or password mismatch
                return(new UnauthorizedResult());
            }
            try
            {
                await DbSeeder.SeedUsers(dbContext, RoleManager, UserManager);
            }
            catch (System.Exception e)
            {
                return(new Object[] { "error", e });

                throw;
            }
            string now = DateTimeOffset.Now.ToString();

            return(new string[] { "Seed succesfull", now });
        }