public UsersController(ServiceJWT jwtService, UserManager <AcUser> um, SignInManager <AcUser> sm, RoleManager <IdentityRole> rm, IMapper mapper) { this.jwtService = jwtService; this.sm = sm; this.rm = rm; this.mapper = mapper; this.um = um; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); if (env.EnvironmentName == "Development") { // services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddDbContext <ApplicationDbContext>(options => options.UseMySql(Configuration.GetConnectionString("DevelopmentMySQL"))); } else { services.AddDbContext <ApplicationDbContext>(options => options.UseMySql(Configuration.GetConnectionString("ProductionMySQL"))); } services.AddScoped(typeof(IRepository <>), typeof(DbRepository <>)); services.AddIdentity <AcUser, IdentityRole>(opt => { opt.Password.RequireDigit = false; opt.Password.RequireNonAlphanumeric = false; opt.Password.RequireLowercase = false; opt.Password.RequireUppercase = false; opt.Password.RequiredLength = 4; opt.Password.RequiredUniqueChars = 2; opt.Lockout.MaxFailedAccessAttempts = 10; opt.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10); }) .AddRoles <IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddScoped <IUserClaimsPrincipalFactory <AcUser>, UserClaimsPrincipalFactory <AcUser, IdentityRole> >(); var mappingConfig = new MapperConfiguration(mc => { mc.AddMaps(new[] { "DataTransferObjects", "Infrastructure.Models" }); mc.AddProfile(new MaProfile()); }); var JWTsettingsSection = Configuration.GetSection("JwtSettings"); services.Configure <JWTSettings>(JWTsettingsSection); var jwtSettings = JWTsettingsSection.Get <JWTSettings>(); services.AddSignalR(); services.AddControllers().AddNewtonsoftJson(); services.Configure <FormOptions>(o => { o.ValueCountLimit = int.MaxValue; o.MultipartBodyLengthLimit = int.MaxValue; o.MemoryBufferThreshold = int.MaxValue; }); services.AddCors(options => { options.AddPolicy("development", builder => { builder.WithOrigins("http://localhost:4200", "http://localhost:5020") .AllowAnyMethod() .AllowAnyHeader(); }); options.AddPolicy("production", builder => { builder.WithOrigins("www.acresh.nsh7.tk", "acresh.nsh7.tk", "https://acresh.nsh7.tk", "https://www.acresh.nsh7.tk") .AllowAnyMethod() .AllowAnyHeader(); }); }); //Configuring OfJWTHappensHere ServiceJWT.ConfigureJWTAUth(services, jwtSettings.Secret, jwtSettings.Issuer); services.AddSingleton <Random>(); IMapper mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); services.AddScoped <DataBaseSeeder>(); services.AddScoped <ServiceJWT>(); services.AddTransient <IUserDataService, UserDataService>(); services.AddTransient <IMessageService, MessageService>(); services.AddTransient <IRecipesService, RecipeService>(); services.AddTransient <ICategoryService, CategoryService>(); services.AddTransient <IIngredientService, IngredientService>(); services.AddTransient <ICommentService, CommentService>(); services.AddResponseCompression(opt => opt.EnableForHttps = true); }
public UserDataController(IUserDataService userDataService, ServiceJWT jwtService) { this.userDataService = userDataService; this.jwtService = jwtService; }