public void Configure(IApplicationBuilder app, UserManager <MyIdentityUser> userManager, RoleManager <IdentityRole> roleManager, MyProductionDbContext context) { if (_hostingEnvironment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "Areas", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}" ); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); MyIdentityInitializer.SeedData(userManager, roleManager, context); }
public AccountsController(UserManager <MyIdentityUser> userManager, SignInManager <MyIdentityUser> signInManager, RoleManager <IdentityRole> roleManager, SignInManager <MyIdentityUser> signinManager, MyProductionDbContext context) { _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; _identityContext = context; }
public static void SeedData( UserManager <MyIdentityUser> userManager, RoleManager <IdentityRole> roleManager, MyProductionDbContext context ) { if (!roleManager.RoleExistsAsync("User").Result) { SeedRoles(roleManager); SeedUsers(userManager); SeedRequests(context, userManager); } }
public static void SeedRequests(MyProductionDbContext context, UserManager <MyIdentityUser> userManager) { // users MyIdentityUser zafer = userManager.FindByNameAsync("zafer").Result; MyIdentityUser mattar = userManager.FindByNameAsync("mattar").Result; MyIdentityUser josh = userManager.FindByNameAsync("josh").Result; //drivers MyIdentityUser gavin = userManager.FindByNameAsync("gavin").Result; MyIdentityUser sean = userManager.FindByNameAsync("sean").Result; MyIdentityUser anas = userManager.FindByNameAsync("anas").Result; RequestModel zaferRequest = new RequestModel { Item = "Vape", UserId = zafer.Id, DriverId = anas.Id, PickupAddress = anas.Address, DropOffAddress = zafer.Address, Status = "Accepted By Driver", ImageName = "vape.png" }; context.Requests.Add(zaferRequest); RequestModel mattarRequest = new RequestModel { Item = "Hijab", UserId = mattar.Id, PickupAddress = gavin.Address, DropOffAddress = gavin.Address, Status = "Awaiting Driver", ImageName = "hijab.jpg" }; context.Requests.Add(mattarRequest); RequestModel joshRequest = new RequestModel { Item = "American flag", UserId = josh.Id, PickupAddress = sean.Address, DropOffAddress = sean.Address, Status = "Awaiting Driver", ImageName = "flag.jpg" }; context.Requests.Add(joshRequest); context.SaveChanges(); }
public AccountsController(MyProductionDbContext context, UserManager <MyIdentityUser> userManager) { _context = context; _userManager = userManager; }
public void ConfigureServices(IServiceCollection services) { string connection = ""; if (_hostingEnvironment.IsDevelopment()) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { connection = Configuration.GetConnectionString("DefaultWinConnection"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { connection = Configuration.GetConnectionString("DefaultMacConnection"); } services.AddDbContext <MyProductionDbContext>(options => options.UseSqlite(connection)); var optionsBuilder = new DbContextOptionsBuilder <MyProductionDbContext>(); optionsBuilder.UseSqlite(connection); var db = new MyProductionDbContext(optionsBuilder.Options); services.AddSingleton <IDbContext>(db); } else { connection = Configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder <MyProductionDbContext>(); optionsBuilder.UseSqlServer(connection); var db = new MyProductionDbContext(optionsBuilder.Options); services.AddSingleton <IDbContext>(db); services.AddDbContext <MyProductionDbContext>( options => options.UseSqlServer(connection) ); } Debug.WriteLine("You are using connection string: " + connection); services.AddIdentity <MyIdentityUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 4; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; }).AddEntityFrameworkStores <MyProductionDbContext>(); services.ConfigureApplicationCookie(options => { options.AccessDeniedPath = new PathString("/Accounts/BecomeDriver"); }); services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.ConfigureApplicationCookie(options => options.LoginPath = "/Accounts/Login"); }