Résolution des conflits

develop
jboinembalome 4 years ago
commit d19d74746c
  1. 15
      Controllers/CollaborateursApi.cs
  2. 1
      EPAServeur.csproj
  3. 24
      Services/EngagementService.cs
  4. 40
      Services/FormationService.cs
  5. 63
      Startup.cs
  6. 4
      appsettings.json

@ -24,6 +24,7 @@ using EPAServeur.Exceptions;
using IO.Swagger.ClientCollaborateur; using IO.Swagger.ClientCollaborateur;
using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace IO.Swagger.Controllers namespace IO.Swagger.Controllers
{ {
@ -50,7 +51,7 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response> /// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs/{idCollaborateur}")] [Route("/api/collaborateurs/{idCollaborateur}")]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "RH,Assistante,Commercial")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetCollaborateurById")] [SwaggerOperation("GetCollaborateurById")]
[SwaggerResponse(statusCode: 200, type: typeof(CollaborateurDTO), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(CollaborateurDTO), description: "OK")]
@ -72,7 +73,7 @@ namespace IO.Swagger.Controllers
} }
catch (CollaborateurNotFoundException) catch (CollaborateurNotFoundException)
{ {
logger.LogError("Le ccollaborateur {id} est introuvable", idCollaborateur); logger.LogError("Le collaborateur {id} est introuvable", idCollaborateur);
ErreurDTO erreurDTO = new ErreurDTO() ErreurDTO erreurDTO = new ErreurDTO()
{ {
Code = "404", Code = "404",
@ -98,7 +99,7 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response> /// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs/mail/{mail}")] [Route("/api/collaborateurs/mail/{mail}")]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "RH,Assistante,Commercial")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetCollaborateurByMail")] [SwaggerOperation("GetCollaborateurByMail")]
[SwaggerResponse(statusCode: 200, type: typeof(CollaborateurDTO), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(CollaborateurDTO), description: "OK")]
@ -116,7 +117,7 @@ namespace IO.Swagger.Controllers
} }
catch (CollaborateurNotFoundException) catch (CollaborateurNotFoundException)
{ {
logger.LogError("Le ccollaborateur {mail} est introuvable", mail); logger.LogError("Le collaborateur {mail} est introuvable", mail);
ErreurDTO erreurDTO = new ErreurDTO() ErreurDTO erreurDTO = new ErreurDTO()
{ {
Code = "404", Code = "404",
@ -152,7 +153,7 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response> /// <response code="403">Acces interdit</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs")] [Route("/api/collaborateurs")]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "RH,Assistante,Commercial")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetCollaborateurs")] [SwaggerOperation("GetCollaborateurs")]
[SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), description: "OK")]
@ -195,7 +196,7 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response> /// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs/referent/{idReferent}")] [Route("/api/collaborateurs/referent/{idReferent}")]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "RH,Assistante,Commercial")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetCollaborateursByReferent")] [SwaggerOperation("GetCollaborateursByReferent")]
[SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), description: "OK")]
@ -242,7 +243,7 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response> /// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs/profil/{mail}/")] [Route("/api/collaborateurs/profil/{mail}/")]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "RH,Assistante,Commercial")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetProfilCollaborateurByMail")] [SwaggerOperation("GetProfilCollaborateurByMail")]
[SwaggerResponse(statusCode: 200, type: typeof(ProfilDTO), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(ProfilDTO), description: "OK")]

@ -6,6 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.21" /> <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.21" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />

@ -54,9 +54,9 @@ namespace EPAServeur.Services
int take = parPAge.Value; int take = parPAge.Value;
if (idAgence != null) if (idAgence != null)
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence); engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence).Skip(skip).Take(take);
else else
engagements = epContext.Engagement.Include(engagement => engagement.Ep); engagements = epContext.Engagement.Include(engagement => engagement.Ep).Skip(skip).Take(take);
if (engagements == null || engagements.Count() == 0) if (engagements == null || engagements.Count() == 0)
return new List<EngagementDTO>(); return new List<EngagementDTO>();
@ -79,9 +79,9 @@ namespace EPAServeur.Services
int take = parPAge.Value; int take = parPAge.Value;
if (idAgence != null) if (idAgence != null)
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence).ToListAsync(); engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence).Skip(skip).Take(take).ToListAsync();
else else
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).ToListAsync(); engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Skip(skip).Take(take).ToListAsync();
if (engagements == null || engagements.Count() == 0) if (engagements == null || engagements.Count() == 0)
return new List<EngagementDTO>(); return new List<EngagementDTO>();
@ -105,9 +105,9 @@ namespace EPAServeur.Services
int take = parPAge.Value; int take = parPAge.Value;
if (idAgence != null) if (idAgence != null)
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).ToList(); engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).Skip(skip).Take(take).ToList();
else else
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).ToList(); engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).Skip(skip).Take(take).ToList();
if (engagements == null || engagements.Count() == 0) if (engagements == null || engagements.Count() == 0)
return new List<EngagementDTO>(); return new List<EngagementDTO>();
@ -130,9 +130,9 @@ namespace EPAServeur.Services
int take = parPAge.Value; int take = parPAge.Value;
if (idAgence != null) if (idAgence != null)
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).ToListAsync(); engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Realise == null).Skip(skip).Take(take).ToListAsync();
else else
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).ToListAsync(); engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise == null).Skip(skip).Take(take).ToListAsync();
if (engagements == null || engagements.Count() == 0) if (engagements == null || engagements.Count() == 0)
return new List<EngagementDTO>(); return new List<EngagementDTO>();
@ -156,9 +156,9 @@ namespace EPAServeur.Services
int take = parPAge.Value; int take = parPAge.Value;
if (idAgence != null) if (idAgence != null)
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Modalite.ToLower().Contains(texte)); engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take);
else else
engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)); engagements = epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take);
if (engagements == null || engagements.Count() == 0) if (engagements == null || engagements.Count() == 0)
return new List<EngagementDTO>(); return new List<EngagementDTO>();
@ -181,9 +181,9 @@ namespace EPAServeur.Services
int take = parPAge.Value; int take = parPAge.Value;
if (idAgence != null) if (idAgence != null)
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Modalite.ToLower().Contains(texte)).ToListAsync(); engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Ep.IdAgence == idAgence && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take).ToListAsync();
else else
engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)).ToListAsync(); engagements = await epContext.Engagement.Include(engagement => engagement.Ep).Where(engagement => engagement.Realise != null && engagement.Modalite.ToLower().Contains(texte)).Skip(skip).Take(take).ToListAsync();
if (engagements == null || engagements.Count() == 0) if (engagements == null || engagements.Count() == 0)
return new List<EngagementDTO>(); return new List<EngagementDTO>();

@ -102,7 +102,7 @@ namespace EPAServeur.Services
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation) .Include(formation => formation.TypeFormation)
.Where(formation => formation.Statut.Id == statutFormation && formation.IdAgence == idAgence); .Where(formation => formation.Statut.Id == statutFormation && formation.IdAgence == idAgence).Skip(skip).Take(take);
} }
else if (statutFormation != null && idAgence == null) else if (statutFormation != null && idAgence == null)
{ {
@ -111,7 +111,7 @@ namespace EPAServeur.Services
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation) .Include(formation => formation.TypeFormation)
.Where(formation => formation.Statut.Id == statutFormation); .Where(formation => formation.Statut.Id == statutFormation).Skip(skip).Take(take);
} }
else if (idAgence != null) else if (idAgence != null)
{ {
@ -119,14 +119,14 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
else else
{ {
formations = epContext.Formation.Include(formation => formation.Statut) formations = epContext.Formation.Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
@ -168,7 +168,7 @@ namespace EPAServeur.Services
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation) .Include(formation => formation.TypeFormation)
.Where(formation => formation.Statut.Id == statutFormation && formation.IdAgence == idAgence).ToListAsync(); .Where(formation => formation.Statut.Id == statutFormation && formation.IdAgence == idAgence).Skip(skip).Take(take).ToListAsync();
} }
else if (statutFormation != null && idAgence == null) else if (statutFormation != null && idAgence == null)
{ {
@ -177,7 +177,7 @@ namespace EPAServeur.Services
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation) .Include(formation => formation.TypeFormation)
.Where(formation => formation.Statut.Id == statutFormation).ToListAsync(); .Where(formation => formation.Statut.Id == statutFormation).Skip(skip).Take(take).ToListAsync();
} }
else if (idAgence != null) else if (idAgence != null)
{ {
@ -186,7 +186,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).Where(formation => formation.IdAgence == idAgence).ToListAsync(); .Include(formation => formation.TypeFormation).Where(formation => formation.IdAgence == idAgence).Skip(skip).Take(take).ToListAsync();
} }
else else
@ -195,7 +195,7 @@ namespace EPAServeur.Services
formations = await epContext.Formation.Include(formation => formation.Statut) formations = await epContext.Formation.Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
} }
@ -236,13 +236,13 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
else else
formations = epContext.Formation.Where(formation => formation.Statut.Id == 4) formations = epContext.Formation.Where(formation => formation.Statut.Id == 4)
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
if (formations == null) if (formations == null)
return null; return null;
@ -280,13 +280,13 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
else else
formations = await epContext.Formation.Where(formation => formation.Statut.Id == 4) formations = await epContext.Formation.Where(formation => formation.Statut.Id == 4)
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
if (formations == null) if (formations == null)
return null; return null;
@ -326,7 +326,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
else else
@ -336,7 +336,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
@ -379,7 +379,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
} }
else else
@ -389,7 +389,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
} }
@ -430,7 +430,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
else else
@ -439,7 +439,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
if (formations == null) if (formations == null)
@ -479,7 +479,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
} }
@ -489,7 +489,7 @@ namespace EPAServeur.Services
.Include(formation => formation.Statut) .Include(formation => formation.Statut)
.Include(formation => formation.ModeFormation) .Include(formation => formation.ModeFormation)
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
} }
if (formations == null) if (formations == null)

@ -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;
@ -16,14 +16,16 @@ namespace EPAServeur
{ {
public class Startup public class Startup
{ {
readonly string AllowCrossClientEPA = "_AllowsCrossOriginClientEPA"; readonly string AllowCrossClientEPA = "_AllowsCrossOriginClientEPA";
public Startup(IConfiguration configuration)
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{ {
Configuration = configuration; Configuration = configuration;
Environment = env;
} }
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
public IWebHostEnvironment Environment { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
@ -38,11 +40,51 @@ namespace EPAServeur
}); });
services.AddControllers(); services.AddControllers();
services.AddAuthentication(BearerAuthenticationHandler.SchemeName)
.AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null); services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(o =>
{
o.Authority = Configuration["Jwt:Authority"];
o.Audience = Configuration["Jwt:Audience"];
if (Environment.IsDevelopment())
{
o.RequireHttpsMetadata = false;
}
o.Events = new JwtBearerEvents()
{
OnAuthenticationFailed = c =>
{
c.NoResult();
c.Response.StatusCode = 500;
c.Response.ContentType = "text/plain";
if (Environment.IsDevelopment())
{
return c.Response.WriteAsync(c.Exception.ToString());
}
return c.Response.WriteAsync("Une erreur s'est produite lors du processus d'authentification.");
},
OnForbidden = c =>
{
c.NoResult();
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>(); services.AddDbContext<EpContext>();
using(var context = new 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.EnsureDeleted(); //PENSEZ A ENLEVER CETTE LIGNE ET A NE JAMAIS LA REMETTRE QUAND LE SERVEUR SERA MIS EN PRODUCTION ^^
context.Database.EnsureCreated(); context.Database.EnsureCreated();
@ -66,13 +108,14 @@ namespace EPAServeur
services.AddScoped<INoteService, NoteService>(); services.AddScoped<INoteService, NoteService>();
services.AddScoped<IReferentService, ReferentService>(); services.AddScoped<IReferentService, ReferentService>();
services.AddScoped<IEngagementService, EngagementService>(); services.AddScoped<IEngagementService, EngagementService>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // 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) public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory logger)
{ {
string path = Directory.GetCurrentDirectory(); string path = Directory.GetCurrentDirectory();
logger.AddFile(path+"Log/loggerfile-{Date}.txt"); logger.AddFile(path + "Log/loggerfile-{Date}.txt");
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
@ -84,12 +127,16 @@ namespace EPAServeur
app.UseCors(AllowCrossClientEPA); app.UseCors(AllowCrossClientEPA);
app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapControllers(); endpoints.MapControllers();
}); });
} }
} }
} }

@ -1,4 +1,8 @@
{ {
"Jwt": {
"Authority": "http://localhost:8080/auth/realms/Apside",
"Audience": "account"
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",

Loading…
Cancel
Save