diff --git a/Back/skydiveLogs-api/Controllers/AircraftController.cs b/Back/skydiveLogs-api/Controllers/AircraftController.cs index 9c663db..82efbad 100644 --- a/Back/skydiveLogs-api/Controllers/AircraftController.cs +++ b/Back/skydiveLogs-api/Controllers/AircraftController.cs @@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers { [Route("api/[controller]")] [ApiController] - public class AircraftController : ControllerBase + public class AircraftController : Base { public AircraftController(IAircraftService aircraftService, IMapper mapper) diff --git a/Back/skydiveLogs-api/Controllers/Base.cs b/Back/skydiveLogs-api/Controllers/Base.cs new file mode 100644 index 0000000..267311a --- /dev/null +++ b/Back/skydiveLogs-api/Controllers/Base.cs @@ -0,0 +1,30 @@ +using System; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNetCore.Mvc; + +using skydiveLogs_api.Model; + + +namespace skydiveLogs_api.Controllers +{ + public class Base : ControllerBase + { + public User ConnectedUser + { + get + { + if (_connectedUser == null) + { + _connectedUser = new User(); + _connectedUser.Login = User.Claims.Single(c => c.Type == ClaimTypes.Name).Value; + _connectedUser.Id = Convert.ToInt32(User.Claims.Single(c => c.Type == ClaimTypes.UserData).Value); + } + + return _connectedUser; + } + } + + private User _connectedUser; + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/Controllers/DropZoneController.cs b/Back/skydiveLogs-api/Controllers/DropZoneController.cs index 0d60b5a..20085b2 100644 --- a/Back/skydiveLogs-api/Controllers/DropZoneController.cs +++ b/Back/skydiveLogs-api/Controllers/DropZoneController.cs @@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers { [Route("api/[controller]")] [ApiController] - public class DropZoneController : ControllerBase + public class DropZoneController : Base { public DropZoneController(IDropZoneService dropZoneService, IMapper mapper) diff --git a/Back/skydiveLogs-api/Controllers/GearController.cs b/Back/skydiveLogs-api/Controllers/GearController.cs index 7c0ff36..4fddf33 100644 --- a/Back/skydiveLogs-api/Controllers/GearController.cs +++ b/Back/skydiveLogs-api/Controllers/GearController.cs @@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers { [Route("api/[controller]")] [ApiController] - public class GearController : ControllerBase + public class GearController : Base { public GearController(IGearService gearService, IMapper mapper) diff --git a/Back/skydiveLogs-api/Controllers/JumpController.cs b/Back/skydiveLogs-api/Controllers/JumpController.cs index 0f6af87..3640ce0 100644 --- a/Back/skydiveLogs-api/Controllers/JumpController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpController.cs @@ -10,13 +10,15 @@ using skydiveLogs_api.Business.Interface; using skydiveLogs_api.DataContract; using skydiveLogs_api.Model; +using System.Linq; +using System.Security.Claims; namespace skydiveLogs_api.Controllers { [Route("api/[controller]")] [ApiController] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] - public class JumpController : ControllerBase + public class JumpController : Base { public JumpController(IJumpService jumpService, IMapper mapper) @@ -30,8 +32,7 @@ namespace skydiveLogs_api.Controllers [EnableCors] public IEnumerable Get() { - var connectedUser = new User() { Id = 1 }; // TEST - var result = _jumpService.GetAllJumps(connectedUser); + var result = _jumpService.GetAllJumps(ConnectedUser); return _mapper.Map>(result); } @@ -55,7 +56,7 @@ namespace skydiveLogs_api.Controllers value.JumpTypeId, value.GearId, _mapper.Map(value), - null /* Provenant du token */); + ConnectedUser); } // PUT: api/Jump/5 diff --git a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs index 676ef50..0f4633c 100644 --- a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs @@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers { [Route("api/[controller]")] [ApiController] - public class JumpTypeController : ControllerBase + public class JumpTypeController : Base { public JumpTypeController(IJumpTypeService jumpTypeService, IMapper mapper) diff --git a/Back/skydiveLogs-api/Controllers/StatsController.cs b/Back/skydiveLogs-api/Controllers/StatsController.cs index f831730..adcfbad 100644 --- a/Back/skydiveLogs-api/Controllers/StatsController.cs +++ b/Back/skydiveLogs-api/Controllers/StatsController.cs @@ -12,7 +12,7 @@ namespace skydiveLogs_api.Controllers { [Route("api/[controller]")] [ApiController] - public class StatsController : ControllerBase + public class StatsController : Base { public StatsController(IStatsService statsService, IMapper mapper) diff --git a/Back/skydiveLogs-api/Startup.cs b/Back/skydiveLogs-api/Startup.cs index c020106..8d9ab2b 100644 --- a/Back/skydiveLogs-api/Startup.cs +++ b/Back/skydiveLogs-api/Startup.cs @@ -67,6 +67,7 @@ namespace skydiveLogs_api var iocService = new IocService(services, Configuration); iocService.Configure(); + // AutoMapper services.AddAutoMapper(typeof(Mapper.ModelProfile)); } diff --git a/Back/skydiveLogs-api/appsettings.Development.json b/Back/skydiveLogs-api/appsettings.Development.json index a639a5a..f80833b 100644 --- a/Back/skydiveLogs-api/appsettings.Development.json +++ b/Back/skydiveLogs-api/appsettings.Development.json @@ -11,7 +11,7 @@ }, "JWT": { "Issuer": "NoIdea", - "Key": "the very long and strong passphrase to crypt the token for DEV" + "Key": "the very long and strong passphrase to encrypt the token for DEV" }, "AllowedHosts": "*", "ConnectionStrings": { diff --git a/Back/skydiveLogs-api/appsettings.Release.json b/Back/skydiveLogs-api/appsettings.Release.json index d231955..e1c309b 100644 --- a/Back/skydiveLogs-api/appsettings.Release.json +++ b/Back/skydiveLogs-api/appsettings.Release.json @@ -9,7 +9,7 @@ }, "JWT": { "Issuer": "NoIdea", - "Key": "the very long and strong passphrase to crypt the token for RELEASE" + "Key": "the very long and strong passphrase to encrypt the token for RELEASE" }, "AllowedHosts": "*", "ConnectionStrings": { diff --git a/Back/skydiveLogs-api/appsettings.json b/Back/skydiveLogs-api/appsettings.json index 58a8453..552c9dc 100644 --- a/Back/skydiveLogs-api/appsettings.json +++ b/Back/skydiveLogs-api/appsettings.json @@ -11,7 +11,7 @@ }, "JWT": { "Issuer": "NoIdea", - "Key": "the very long and strong passphrase to crypt the token" + "Key": "the very long and strong passphrase to encrypt the token" }, "AllowedHosts": "*", "ConnectionStrings": {