// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, RoleManager <IdentityRole> roleManager) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); await RoleInitializer.Initialize(roleManager); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env , RoleManager <ApplicationRole> roleManager , UserManager <ApplicationUser> userManager ) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } 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(); endpoints.MapHub <ChatHub>("/chatHub"); }); RoleInitializer.Initialize(roleManager).Wait(); SetAdmin.AdminAsync(userManager).Wait(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddIdentity <UserApp, IdentityRole>(o => { o.Password.RequireDigit = false; o.Password.RequireLowercase = false; o.Password.RequireUppercase = false; o.Password.RequireNonAlphanumeric = false; o.Password.RequiredLength = 6; }) .AddEntityFrameworkStores <ApplicationContext>() .AddDefaultTokenProviders(); services.AddDbContext <ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("StringConnection"))); services.AddAuthentication().AddCookie(); services.AddServerSideBlazor(); services.AddScoped <ITask, TaskDriver>(); services.AddMvc(); var provider = services.BuildServiceProvider(); //lately cut`s in another class for initialization StartsInitialize.Initialize(); DbInitializer dbInitializer = new DbInitializer(); dbInitializer.Initialize(provider); UserInitialize userInitialize = new UserInitialize(); userInitialize.Initialize(provider); RoleInitializer roleInitializer = new RoleInitializer(); roleInitializer.Initialize(provider); AdminInitialize adminInitialize = new AdminInitialize(); adminInitialize.Initialize(provider); services.AddHangfire((config) => { var options = new SqlServerStorageOptions { PrepareSchemaIfNecessary = true, QueuePollInterval = TimeSpan.FromHours(10) }; config.UseSqlServerStorage("Server=(localdb)\\mssqllocaldb;Database=CostsAnalyseDB;Trusted_Connection=True;MultipleActiveResultSets=true", options); }); }
protected override void Seed(Contexts.ToolContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. DepartmentInitializer.Initialize(context); RoleInitializer.Initialize(context); StockInitializer.Initialize(context); AdminInitializer.Initialize(context); StockKeeperInitializer.Initialize(context); context.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, RoleManager <CustomIdentityRole> roleManager ) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseFileServer(); app.UseNodeModules(env.ContentRootPath); app.UseIdentity(); app.UseSession(); app.UseMvc(ConfigureRoutes); RoleInitializer.Initialize(roleManager); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, RoleManager <IdentityRole> roleManager, IServiceProvider serviceProvider) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); ConnectionManager = serviceProvider.GetService <IConnectionManager>(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseSignalR(); app.UseIdentity(); app.UseSession(); // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); var _context = app.ApplicationServices.GetService <DPHCSContext>(); //Drop all old session in database _context.Database.ExecuteSqlCommand("TRUNCATE TABLE [UserConnection]"); _context.SaveChanges(); await RoleInitializer.Initialize(roleManager); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <User> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.Initialize(roleManager, userManager); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "Возникло исключение при инициализации ролей"); } host.Run(); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { await RoleInitializer.Initialize(_roleManager); await _userManager.AddToRoleAsync(user, Input.Role); _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); //await _signInManager.SignInAsync(user, isPersistent: false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
//Configuration public void Configure( IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, ILoggerFactory loggerFactory, RoleManager <ApplicationRole> roleManager ) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseSession(); var options = new RewriteOptions() .AddRedirectToHttps(); app.UseRewriter(options); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Login}/{id?}"); }); RoleInitializer.Initialize(roleManager); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var configuration = services.GetRequiredService <IConfiguration>(); var unitOfWork = services.GetRequiredService <IUnitOfWork>(); var userService = services.GetRequiredService <IUserService>(); var roleService = services.GetRequiredService <IRoleService>(); var userRoleService = services.GetRequiredService <IUserRoleService>(); DataInitializer.Initialize(unitOfWork, configuration); RoleInitializer.Initialize(configuration, userService, roleService, userRoleService); } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseSession(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseSignalR(routes => { routes.MapHub <ChatHub>("/chatHub"); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); RoleInitializer.Initialize(roleManager).Wait(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using var scope = host.Services.CreateScope();; var services = scope.ServiceProvider; try { DataScheduler.Start(services); var userManager = services.GetRequiredService <UserManager <Employee> >(); var roleManager = services.GetRequiredService <RoleManager <Role> >(); await RoleInitializer.Initialize(roleManager, userManager); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "�������� ���������� ��� ������������� �����"); } host.Run(); }