From ce4e06a235efda69c72d34815863d0b367577301 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 8 Dec 2020 18:50:47 +0200 Subject: Added Authen, Author & Config in Startup. Fixed User class --- API/API.csproj | 3 +- API/Database/DbRepository.cs | 4 ++ API/Database/DevHiveContext.cs | 8 ++-- API/Startup.cs | 100 ++++++++++++++++++++++++----------------- 4 files changed, 70 insertions(+), 45 deletions(-) create mode 100644 API/Database/DbRepository.cs (limited to 'API') diff --git a/API/API.csproj b/API/API.csproj index 401d5bc..63231c1 100644 --- a/API/API.csproj +++ b/API/API.csproj @@ -7,8 +7,9 @@ - + + diff --git a/API/Database/DbRepository.cs b/API/Database/DbRepository.cs new file mode 100644 index 0000000..a166682 --- /dev/null +++ b/API/Database/DbRepository.cs @@ -0,0 +1,4 @@ +namespace API.Database +{ + +} \ No newline at end of file diff --git a/API/Database/DevHiveContext.cs b/API/Database/DevHiveContext.cs index 6f2a20c..6db137a 100644 --- a/API/Database/DevHiveContext.cs +++ b/API/Database/DevHiveContext.cs @@ -4,9 +4,9 @@ using Models.Classes; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; -namespace Database +namespace API.Database { - public class DevHiveContext : IdentityDbContext, IdentityRole, int> + public class DevHiveContext : IdentityDbContext, int> { public DevHiveContext(DbContextOptions options) : base(options) { } @@ -16,8 +16,8 @@ namespace Database protected override void OnModelCreating(ModelBuilder builder) { - // builder.Entity() - // .HasKey(x => x.Id); + builder.Entity() + .HasKey(x => x.Id); base.OnModelCreating(builder); } diff --git a/API/Startup.cs b/API/Startup.cs index cd2c39a..9257c0e 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -1,51 +1,71 @@ +using API.Database; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; +using Models.Classes; namespace API { public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddControllers(); - - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); - }); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); - } - - app.UseHttpsRedirection(); - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + + services.AddDbContext(options => + options.UseNpgsql(Configuration.GetConnectionString("DEV"))) + .AddAuthentication() + .AddJwtBearer(); + + services.AddIdentity>(); + //services.AddAuthentication(); + + services.Configure(options => + { + options.User.RequireUniqueEmail = true; + + // options.Password.RequiredLength = 5; + }); + + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); + } + + app.UseHttpsRedirection(); + app.UseRouting(); + + app.UseAuthentication(); + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } } -- cgit v1.2.3