aboutsummaryrefslogtreecommitdiff
path: root/API/Startup.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-08 18:50:47 +0200
committertranstrike <transtrike@gmail.com>2020-12-08 18:50:47 +0200
commitce4e06a235efda69c72d34815863d0b367577301 (patch)
treeb546ded8c948798abbe095b6c7a1bae4794ce952 /API/Startup.cs
parentab0430b95cc440ed671beaf642c5749862e3b6b4 (diff)
downloadDevHive-ce4e06a235efda69c72d34815863d0b367577301.tar
DevHive-ce4e06a235efda69c72d34815863d0b367577301.tar.gz
DevHive-ce4e06a235efda69c72d34815863d0b367577301.zip
Added Authen, Author & Config in Startup. Fixed User class
Diffstat (limited to 'API/Startup.cs')
-rw-r--r--API/Startup.cs100
1 files changed, 60 insertions, 40 deletions
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();
+ });
+ }
+ }
}