diff options
| author | Kamen Mladenov <kamen.d.mladenov@protonmail.com> | 2021-04-09 19:51:35 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-09 19:51:35 +0300 |
| commit | 233f38915ba0079079233eff55434ef349c05c45 (patch) | |
| tree | 6c5f69017865bcab87355e910c87339453da1406 /src/DevHive.Web/Configurations/Extensions | |
| parent | f4a70c6430db923af9fa9958a11c2d6612cb52cc (diff) | |
| parent | a992357efcf1bc1ece81b95ecee5e05a0b73bfdc (diff) | |
| download | DevHive-233f38915ba0079079233eff55434ef349c05c45.tar DevHive-233f38915ba0079079233eff55434ef349c05c45.tar.gz DevHive-233f38915ba0079079233eff55434ef349c05c45.zip | |
Merge pull request #28 from Team-Kaleidoscope/devHEADv0.2mainheroku/main
Second stage: Complete
Diffstat (limited to 'src/DevHive.Web/Configurations/Extensions')
6 files changed, 0 insertions, 225 deletions
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs deleted file mode 100644 index 8b7d657..0000000 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using AutoMapper; -//using AutoMapper.Configuration; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class ConfigureAutoMapper - { - public static void AutoMapperConfiguration(this IServiceCollection services) - { - services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); - } - - public static void UseAutoMapperConfiguration(this IApplicationBuilder app) - { - var config = new MapperConfiguration(cfg => - { - cfg.AllowNullCollections = true; - }); - } - } -}
\ No newline at end of file diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs deleted file mode 100644 index 9f02dd7..0000000 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using DevHive.Data.Models; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Builder; -using System; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using DevHive.Data; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class DatabaseExtensions - { - public static void DatabaseConfiguration(this IServiceCollection services, IConfiguration configuration) - { - services.AddDbContext<DevHiveContext>(options => - { - options.EnableSensitiveDataLogging(true); - options.UseNpgsql(configuration.GetConnectionString("DEV")); - }); - - services.AddIdentity<User, Role>() - .AddRoles<Role>() - .AddEntityFrameworkStores<DevHiveContext>(); - - services.Configure<IdentityOptions>(options => - { - options.User.RequireUniqueEmail = true; - - options.Password.RequireDigit = true; - options.Password.RequiredLength = 5; - options.Password.RequiredUniqueChars = 0; - options.Password.RequireLowercase = false; - options.Password.RequireNonAlphanumeric = false; - options.Password.RequireUppercase = false; - - options.Lockout.AllowedForNewUsers = true; - options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); - options.Lockout.MaxFailedAccessAttempts = 5; - }); - - services.AddAuthorization(options => - { - options.AddPolicy("User", options => - { - options.RequireAuthenticatedUser(); - options.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); - options.RequireRole("User"); - }); - - options.AddPolicy("Administrator", options => - { - options.RequireAuthenticatedUser(); - options.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); - options.RequireRole("Admin"); - }); - }); - } - - public static void UseDatabaseConfiguration(this IApplicationBuilder app) - { - app.UseHttpsRedirection(); - app.UseRouting(); - - app.UseAuthentication(); - app.UseAuthorization(); - } - } -} diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs deleted file mode 100644 index 88f21d4..0000000 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ /dev/null @@ -1,38 +0,0 @@ -using DevHive.Data.Interfaces.Repositories; -using DevHive.Data.Repositories; -using DevHive.Services.Interfaces; -using DevHive.Services.Services; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class ConfigureDependencyInjection - { - public static void DependencyInjectionConfiguration(this IServiceCollection services, IConfiguration configuration) - { - services.AddTransient<ILanguageRepository, LanguageRepository>(); - services.AddTransient<IRoleRepository, RoleRepository>(); - services.AddTransient<ITechnologyRepository, TechnologyRepository>(); - services.AddTransient<IUserRepository, UserRepository>(); - services.AddTransient<IPostRepository, PostRepository>(); - services.AddTransient<ICommentRepository, CommentRepository>(); - services.AddTransient<IFeedRepository, FeedRepository>(); - services.AddTransient<IRatingRepository, RatingRepository>(); - - services.AddTransient<ILanguageService, LanguageService>(); - services.AddTransient<IRoleService, RoleService>(); - services.AddTransient<ITechnologyService, TechnologyService>(); - services.AddTransient<IUserService, UserService>(); - services.AddTransient<IPostService, PostService>(); - services.AddTransient<ICommentService, CommentService>(); - services.AddTransient<IFeedService, FeedService>(); - services.AddTransient<ICloudService, CloudinaryService>(options => - new CloudinaryService( - cloudName: configuration.GetSection("Cloud").GetSection("cloudName").Value, - apiKey: configuration.GetSection("Cloud").GetSection("apiKey").Value, - apiSecret: configuration.GetSection("Cloud").GetSection("apiSecret").Value)); - services.AddTransient<IRateService, RateService>(); - } - } -} diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs deleted file mode 100644 index 286727f..0000000 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs +++ /dev/null @@ -1,16 +0,0 @@ -using DevHive.Web.Middleware; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class ConfigureExceptionHandlerMiddleware - { - public static void ExceptionHandlerMiddlewareConfiguration(this IServiceCollection services) { } - - public static void UseExceptionHandlerMiddlewareConfiguration(this IApplicationBuilder app) - { - app.UseMiddleware<ExceptionMiddleware>(); - } - } -} diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs deleted file mode 100644 index d422bc8..0000000 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Text; -using System.Threading.Tasks; -using DevHive.Services.Options; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.IdentityModel.Tokens; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class JWTExtensions - { - public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration) - { - services.AddSingleton(new JWTOptions(configuration - .GetSection("AppSettings") - .GetSection("Secret") - .Value)); - - // Get key from appsettings.json - var key = Encoding.ASCII.GetBytes(configuration - .GetSection("AppSettings") - .GetSection("Secret") - .Value); - - // Setup Jwt Authentication - services.AddAuthentication(x => - { - x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }) - .AddJwtBearer(x => - { - x.Events = new JwtBearerEvents - { - OnTokenValidated = context => - { - // TODO: add more authentication - return Task.CompletedTask; - } - }; - x.RequireHttpsMetadata = false; - x.SaveToken = true; - x.TokenValidationParameters = new TokenValidationParameters - { - //ValidateIssuerSigningKey = false, - IssuerSigningKey = new SymmetricSecurityKey(key), - ValidateIssuer = false, - ValidateAudience = false - }; - }); - } - } -}
\ No newline at end of file diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs deleted file mode 100644 index a0641ab..0000000 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class SwaggerExtensions - { - public static void SwaggerConfiguration(this IServiceCollection services) - { - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); - }); - } - - public static void UseSwaggerConfiguration(this IApplicationBuilder app) - { - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); - } - } -}
\ No newline at end of file |
