// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IPrivilegeService privilegeService, IRoleService roleService, IUserService userService) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseStatusCodePagesWithReExecute("/Home/StatusCodePage", "?code={0}"); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); PrivilegeInitializer.SeedData(privilegeService); RoleInitializer.SeedData(privilegeService, roleService); UserInitializer.SeedData(userService, roleService); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id:int?}"); }); }
public async Task StartAsync() { if (!_started) { _hubConnection = new HubConnectionBuilder().WithUrl(_navigationManager.ToAbsoluteUri(HubUrl)).Build(); } _hubConnection.On(Messages.Receive, (string user, string message) => { ReceiveMessage(user, message); }); _hubConnection.On("CalculateChatPrivateKey", (double key) => { CalculatePrivateChatKey(key); }); _hubConnection.On("OnJoinedNewUser", (User user, string notification) => { DeffieHellman(); }); await _hubConnection.StartAsync(); _started = true; User user = UserInitializer.GetNewUser(_username); await _hubConnection.SendAsync(Messages.Register, user); DeffieHellman(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager) { if (env.IsDevelopment()) { UserInitializer.initialize(userManager); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapHub <BiddingHub>("/update"); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Auction}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, CRSDbContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseCors(bulider => bulider.WithOrigins(Configuration["JWTSettings:Client_URL"].ToString()) .AllowAnyMethod() .AllowAnyHeader()); app.UseHttpsRedirection(); UserInitializer.Initialize(context, userManager, roleManager).Wait(); TypeOfCustomerInitializer.Initialize(context).Wait(); CarModelInitializer.Initialize(context).Wait(); app.UseAuthentication(); app.UseMiddleware(typeof(ErrorHandlingMiddleware)); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scopedService = host.Services.CreateScope()) { UserInitializer.AddUsers(scopedService); } host.Run(); }
public async Task StartAsync(CancellationToken cancellationToken) { using (var scope = _serviceProvider.CreateScope()) { var seeder = new UserInitializer(); await seeder.SeedData( scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(), scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(), scope.ServiceProvider.GetRequiredService <ApplicationDbContext>()); } }
private static void ExecuteInitializers(DatabaseContext context) { /** General */ var languages = new LanguageInitializer(context).Seed(); var users = new UserInitializer(context).Seed(); var permissions = new PermissionInitializer(context).Seed(); var roles = new RoleInitializer(permissions, users, context).Seed(); /** File Manager */ var fileManagerDirectories = new FileManagerDirectoryInitializer(users, context).Seed(); }
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e) { if (User.Identity.IsAuthenticated) { //we will Try to make it more efficient later if (HttpContext.Current.Session != null) { UserLogin AppUser = new UserInitializer().GetCurrentUser(User.Identity.Name); CustomPrincipal UserPrincipal = new CustomPrincipal(AppUser, User.Identity); HttpContext.Current.User = UserPrincipal; } } }
private static void InsertUsers(BillsPaymentSystemContext context) { var users = UserInitializer.GetUsers(); foreach (var u in users) { if (IsValid(u)) { context.Users.Add(u); } } context.SaveChanges(); }
private static void InsertUsers(BillPaymentSystemContext context) { var users = UserInitializer.GetUsers(); for (int i = 0; i < users.Length; i++) { if (IsValid(users[i])) { context.Users.Add(users[i]); } } context.SaveChanges(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var userManager = services.GetRequiredService <UserManager <AppUser> >(); var rolesManager = services.GetRequiredService <RoleManager <AppRole> >(); await UserInitializer.InitializeAsync(userManager, rolesManager); } host.Run(); }
public RegisterModel( UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager, ILogger <RegisterModel> logger, IEmailSender emailSender, RoleManager <IdentityRole> roleManager, UserInitializer initializer) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _emailSender = emailSender; _roleManager = roleManager; _initializer = initializer; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. //use components for request pipeline public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, UserInitializer userInit) { loggerFactory.AddConsole(_config.GetSection("Logging")); loggerFactory.AddDebug(); app.UseIdentity(); app.UseMvc(); app.ApplicationServices.GetRequiredService <ExpenseDb>().Seed(); app.ApplicationServices.GetRequiredService <IdentityDb>().Seed(); userInit.AddUser(app.ApplicationServices.GetRequiredService <IdentityDb>()).Wait(); }
private static async Task InitializeUsers(IWebHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await UserInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseRequestLocalization(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "exam", template: "StartExam/{code?}", defaults: new { controller = "ExamApproaches", action = "Index" }); routes.MapRoute( name: "egzamin", template: "Egzamin/{code?}", defaults: new { controller = "ExamApproaches", action = "Index" }); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); var serviceProvider = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider; var userManager = serviceProvider.GetService <UserManager <IdentityUser> >(); var roleMenager = serviceProvider.GetService <RoleManager <IdentityRole> >(); var initializer = new UserInitializer(roleMenager, userManager, Configuration); initializer.CreateRolesAsync().Wait(); initializer.CreateDefaultUser().Wait(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { var userManager = serviceProvider.GetRequiredService <UserManager <User> >(); var roleManager = serviceProvider.GetRequiredService <RoleManager <Role> >(); await RoleInitializer.SeedRoleAsync(roleManager); await UserInitializer.SeedUsersAsync(userManager); } catch (Exception ex) { Console.WriteLine(ex.Message); } } await host.RunAsync(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; //try //{ var context = services.GetRequiredService <ApplicationDbContext>(); LocationsInitializer.Initialize(context); GirosInitializer.Initialize(context); UserInitializer.Initialize(context); //} //catch (Exception ex) //{ // var logger = services.GetRequiredService<ILogger<Program>>(); // logger.LogError(ex, "Ha ocurrido un error al sembrar la base de datos."); //} } host.Run(); }
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<IdentityUser>>(); var rolesManager = services.GetRequiredService<RoleManager<IdentityRole>>(); await UserInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService<ILogger<Program>>(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); UserInitializer.SeedUsers(context, userManager).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding users"); } } host.Run(); }
public UserService() { _users = UserInitializer.GetSampleUserData(); }