|
|
@ -2,10 +2,10 @@ using EPAServeur.Context; |
|
|
|
using EPAServeur.IServices; |
|
|
|
using EPAServeur.IServices; |
|
|
|
using EPAServeur.Services; |
|
|
|
using EPAServeur.Services; |
|
|
|
using IO.Swagger.ApiCollaborateur; |
|
|
|
using IO.Swagger.ApiCollaborateur; |
|
|
|
using IO.Swagger.Security; |
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
|
|
|
using Microsoft.AspNetCore.Authentication; |
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
@ -14,69 +14,129 @@ using System.IO; |
|
|
|
|
|
|
|
|
|
|
|
namespace EPAServeur |
|
|
|
namespace EPAServeur |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class Startup |
|
|
|
public class Startup |
|
|
|
{ |
|
|
|
{ |
|
|
|
public Startup(IConfiguration configuration) |
|
|
|
readonly string AllowCrossClientEPA = "_AllowsCrossOriginClientEPA"; |
|
|
|
{ |
|
|
|
|
|
|
|
Configuration = configuration; |
|
|
|
public Startup(IConfiguration configuration, IWebHostEnvironment env) |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
Configuration = configuration; |
|
|
|
public IConfiguration Configuration { get; } |
|
|
|
Environment = env; |
|
|
|
|
|
|
|
} |
|
|
|
// This method gets called by the runtime. Use this method to add services to the container. |
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services) |
|
|
|
public IConfiguration Configuration { get; } |
|
|
|
{ |
|
|
|
public IWebHostEnvironment Environment { get; } |
|
|
|
services.AddControllers(); |
|
|
|
|
|
|
|
services.AddAuthentication(BearerAuthenticationHandler.SchemeName) |
|
|
|
// This method gets called by the runtime. Use this method to add services to the container. |
|
|
|
.AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null); |
|
|
|
public void ConfigureServices(IServiceCollection services) |
|
|
|
|
|
|
|
{ |
|
|
|
services.AddDbContext<EpContext>(); |
|
|
|
services.AddCors(options => |
|
|
|
using(var context = new EpContext()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
options.AddPolicy(name: AllowCrossClientEPA, |
|
|
|
context.Database.EnsureDeleted(); //PENSEZ A ENLEVER CETTE LIGNE ET A NE JAMAIS LA REMETTRE QUAND LE SERVEUR SERA MIS EN PRODUCTION ^^ |
|
|
|
builder => |
|
|
|
context.Database.EnsureCreated(); |
|
|
|
{ |
|
|
|
context.SaveChanges(); |
|
|
|
builder.WithOrigins("http://localhost:4200").AllowAnyHeader().AllowAnyMethod(); |
|
|
|
context.AjoutInformationsDeBase(); |
|
|
|
}); |
|
|
|
context.AjoutChamps(); |
|
|
|
}); |
|
|
|
context.AjouterNotes(); |
|
|
|
|
|
|
|
} |
|
|
|
services.AddControllers(); |
|
|
|
//faire using, check si kekchoz exkist puis appeler les m<EFBFBD>thodes de cr<EFBFBD>ation si il n'y a rien |
|
|
|
|
|
|
|
|
|
|
|
services.AddAuthentication(options => |
|
|
|
//API Collaborateurs |
|
|
|
{ |
|
|
|
services.AddScoped<ICollaborateurApi, CollaborateurApi>(); |
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
services.AddScoped<IAgenceApi, AgenceApi>(); |
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
services.AddScoped<IReferentApi, ReferentApi>(); |
|
|
|
}).AddJwtBearer(o => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
o.Authority = Configuration["Jwt:Authority"]; |
|
|
|
|
|
|
|
o.Audience = Configuration["Jwt:Audience"]; |
|
|
|
//Services |
|
|
|
|
|
|
|
services.AddScoped<ICollaborateurService, CollaborateurService>(); |
|
|
|
if (Environment.IsDevelopment()) |
|
|
|
services.AddScoped<IFormationService, FormationService>(); |
|
|
|
{ |
|
|
|
services.AddScoped<INoteService, NoteService>(); |
|
|
|
o.RequireHttpsMetadata = false; |
|
|
|
services.AddScoped<IReferentService, ReferentService>(); |
|
|
|
} |
|
|
|
services.AddScoped<IEngagementService, EngagementService>(); |
|
|
|
|
|
|
|
} |
|
|
|
o.Events = new JwtBearerEvents() |
|
|
|
|
|
|
|
{ |
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
|
|
|
OnAuthenticationFailed = c => |
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory logger) |
|
|
|
{ |
|
|
|
{ |
|
|
|
c.NoResult(); |
|
|
|
string path = Directory.GetCurrentDirectory(); |
|
|
|
|
|
|
|
logger.AddFile(path+"Log/loggerfile-{Date}.txt"); |
|
|
|
c.Response.StatusCode = 500; |
|
|
|
if (env.IsDevelopment()) |
|
|
|
c.Response.ContentType = "text/plain"; |
|
|
|
{ |
|
|
|
|
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
if (Environment.IsDevelopment()) |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
return c.Response.WriteAsync(c.Exception.ToString()); |
|
|
|
app.UseHttpsRedirection(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
app.UseRouting(); |
|
|
|
return c.Response.WriteAsync("Une erreur s'est produite lors du processus d'authentification."); |
|
|
|
|
|
|
|
}, |
|
|
|
app.UseAuthorization(); |
|
|
|
OnForbidden = c => |
|
|
|
|
|
|
|
{ |
|
|
|
app.UseEndpoints(endpoints => |
|
|
|
c.NoResult(); |
|
|
|
{ |
|
|
|
|
|
|
|
endpoints.MapControllers(); |
|
|
|
c.Response.StatusCode = 403; |
|
|
|
}); |
|
|
|
c.Response.ContentType = "text/plain"; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return c.Response.WriteAsync("L'utilisateur n'est pas autorisé à accéder à cette ressource."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.AddDbContext<EpContext>(); |
|
|
|
|
|
|
|
using (var context = new EpContext()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
context.Database.EnsureDeleted(); //PENSEZ A ENLEVER CETTE LIGNE ET A NE JAMAIS LA REMETTRE QUAND LE SERVEUR SERA MIS EN PRODUCTION ^^ |
|
|
|
|
|
|
|
context.Database.EnsureCreated(); |
|
|
|
|
|
|
|
context.SaveChanges(); |
|
|
|
|
|
|
|
context.AjoutInformationsDeBase(); |
|
|
|
|
|
|
|
context.AjoutChamps(); |
|
|
|
|
|
|
|
context.AjouterNotes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//faire using, check si kekchoz exkist puis appeler les m<EFBFBD>thodes de cr<EFBFBD>ation si il n'y a rien |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//API Collaborateurs |
|
|
|
|
|
|
|
services.AddScoped<ICollaborateurApi, CollaborateurApi>(); |
|
|
|
|
|
|
|
services.AddScoped<IAgenceApi, AgenceApi>(); |
|
|
|
|
|
|
|
services.AddScoped<IReferentApi, ReferentApi>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Services |
|
|
|
|
|
|
|
services.AddScoped<ICollaborateurService, CollaborateurService>(); |
|
|
|
|
|
|
|
services.AddScoped<IFormationService, FormationService>(); |
|
|
|
|
|
|
|
services.AddScoped<INoteService, NoteService>(); |
|
|
|
|
|
|
|
services.AddScoped<IReferentService, ReferentService>(); |
|
|
|
|
|
|
|
services.AddScoped<IEngagementService, EngagementService>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory logger) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string path = Directory.GetCurrentDirectory(); |
|
|
|
|
|
|
|
logger.AddFile(path + "Log/loggerfile-{Date}.txt"); |
|
|
|
|
|
|
|
if (env.IsDevelopment()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.UseRouting(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.UseCors(AllowCrossClientEPA); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.UseAuthentication(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
endpoints.MapControllers(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|