aboutsummaryrefslogtreecommitdiff
path: root/API/Extensions/ConfigureDatabase.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2020-12-12 15:07:44 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2020-12-12 15:07:44 +0200
commite7912e18285f0381e66e78da948c0cd37a06fbd7 (patch)
treecf68b2f7778a22c901604c86603b5455af63bc80 /API/Extensions/ConfigureDatabase.cs
parent811ac5c6ea42174854cd525f0dee9ce6363ee739 (diff)
parent8bd7295dc4694c1c0ed6fbc05d390223bfc4ef05 (diff)
downloadDevHive-e7912e18285f0381e66e78da948c0cd37a06fbd7.tar
DevHive-e7912e18285f0381e66e78da948c0cd37a06fbd7.tar.gz
DevHive-e7912e18285f0381e66e78da948c0cd37a06fbd7.zip
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into autorization-dev
Diffstat (limited to 'API/Extensions/ConfigureDatabase.cs')
-rw-r--r--API/Extensions/ConfigureDatabase.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/API/Extensions/ConfigureDatabase.cs b/API/Extensions/ConfigureDatabase.cs
new file mode 100644
index 0000000..57560e2
--- /dev/null
+++ b/API/Extensions/ConfigureDatabase.cs
@@ -0,0 +1,42 @@
+using Microsoft.Extensions.DependencyInjection;
+using API.Database;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using Data.Models.Classes;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Builder;
+
+namespace API.Extensions
+{
+ public static class DatabaseExtensions
+ {
+ public static void DatabaseConfiguration(this IServiceCollection services, IConfiguration configuration)
+ {
+ services.AddDbContext<DevHiveContext>(options =>
+ options.UseNpgsql(configuration.GetConnectionString("DEV")))
+ .AddAuthentication()
+ .AddJwtBearer();
+
+ services.AddIdentity<User, Roles>()
+ .AddEntityFrameworkStores<DevHiveContext>();
+
+ services.AddAuthentication();
+
+ services.Configure<IdentityOptions>(options =>
+ {
+ options.User.RequireUniqueEmail = true;
+
+ options.Password.RequiredLength = 5;
+ });
+ }
+
+ public static void UseDatabaseConfiguration(this IApplicationBuilder app)
+ {
+ app.UseHttpsRedirection();
+ app.UseRouting();
+
+ app.UseAuthentication();
+ app.UseAuthorization();
+ }
+ }
+} \ No newline at end of file