diff options
| author | transtrike <transtrike@gmail.com> | 2020-12-08 18:50:47 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2020-12-08 18:50:47 +0200 |
| commit | ce4e06a235efda69c72d34815863d0b367577301 (patch) | |
| tree | b546ded8c948798abbe095b6c7a1bae4794ce952 | |
| parent | ab0430b95cc440ed671beaf642c5749862e3b6b4 (diff) | |
| download | DevHive-ce4e06a235efda69c72d34815863d0b367577301.tar DevHive-ce4e06a235efda69c72d34815863d0b367577301.tar.gz DevHive-ce4e06a235efda69c72d34815863d0b367577301.zip | |
Added Authen, Author & Config in Startup. Fixed User class
| -rw-r--r-- | API/API.csproj | 3 | ||||
| -rw-r--r-- | API/Database/DbRepository.cs | 4 | ||||
| -rw-r--r-- | API/Database/DevHiveContext.cs | 8 | ||||
| -rw-r--r-- | API/Startup.cs | 100 | ||||
| -rw-r--r-- | Models/Classes/User.cs | 4 |
5 files changed, 72 insertions, 47 deletions
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 @@ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" NoWarn="NU1605"/> <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" NoWarn="NU1605"/> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3"/> - <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0"/> + <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1"/> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0"/> + <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0"/> </ItemGroup> <ItemGroup> <ProjectReference Include="..\Models\Models.csproj"/> 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<User<int>, IdentityRole<int>, int> + public class DevHiveContext : IdentityDbContext<User, IdentityRole<int>, int> { public DevHiveContext(DbContextOptions options) : base(options) { } @@ -16,8 +16,8 @@ namespace Database protected override void OnModelCreating(ModelBuilder builder) { - // builder.Entity<User>() - // .HasKey(x => x.Id); + builder.Entity<User>() + .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<DevHiveContext>(options =>
+ options.UseNpgsql(Configuration.GetConnectionString("DEV")))
+ .AddAuthentication()
+ .AddJwtBearer();
+
+ services.AddIdentity<User, IdentityRole<int>>();
+ //services.AddAuthentication();
+
+ services.Configure<IdentityOptions>(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();
+ });
+ }
+ }
}
diff --git a/Models/Classes/User.cs b/Models/Classes/User.cs index bbc05bf..1e3b946 100644 --- a/Models/Classes/User.cs +++ b/Models/Classes/User.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; namespace Models.Classes { [Table("Users")] - public class User<T> : IdentityUser<int> + public class User : IdentityUser<int> { private string firstName; private string lastName; @@ -60,7 +60,7 @@ namespace Models.Classes } } - public List<User<T>> Friends { get; set; } + public List<User> Friends { get; set; } /// <summary> /// Throws an argument exception if the given value is not composed only of letters, and if specified, also of digits. |
