Add a property to retrieve the claims (id and login) in the token
This commit is contained in:
@@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class AircraftController : ControllerBase
|
public class AircraftController : Base
|
||||||
{
|
{
|
||||||
public AircraftController(IAircraftService aircraftService,
|
public AircraftController(IAircraftService aircraftService,
|
||||||
IMapper mapper)
|
IMapper mapper)
|
||||||
|
|||||||
30
Back/skydiveLogs-api/Controllers/Base.cs
Normal file
30
Back/skydiveLogs-api/Controllers/Base.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DropZoneController : ControllerBase
|
public class DropZoneController : Base
|
||||||
{
|
{
|
||||||
public DropZoneController(IDropZoneService dropZoneService,
|
public DropZoneController(IDropZoneService dropZoneService,
|
||||||
IMapper mapper)
|
IMapper mapper)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class GearController : ControllerBase
|
public class GearController : Base
|
||||||
{
|
{
|
||||||
public GearController(IGearService gearService,
|
public GearController(IGearService gearService,
|
||||||
IMapper mapper)
|
IMapper mapper)
|
||||||
|
|||||||
@@ -10,13 +10,15 @@ using skydiveLogs_api.Business.Interface;
|
|||||||
using skydiveLogs_api.DataContract;
|
using skydiveLogs_api.DataContract;
|
||||||
using skydiveLogs_api.Model;
|
using skydiveLogs_api.Model;
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace skydiveLogs_api.Controllers
|
namespace skydiveLogs_api.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||||
public class JumpController : ControllerBase
|
public class JumpController : Base
|
||||||
{
|
{
|
||||||
public JumpController(IJumpService jumpService,
|
public JumpController(IJumpService jumpService,
|
||||||
IMapper mapper)
|
IMapper mapper)
|
||||||
@@ -30,8 +32,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
[EnableCors]
|
[EnableCors]
|
||||||
public IEnumerable<JumpResp> Get()
|
public IEnumerable<JumpResp> Get()
|
||||||
{
|
{
|
||||||
var connectedUser = new User() { Id = 1 }; // TEST
|
var result = _jumpService.GetAllJumps(ConnectedUser);
|
||||||
var result = _jumpService.GetAllJumps(connectedUser);
|
|
||||||
|
|
||||||
return _mapper.Map<IEnumerable<JumpResp>>(result);
|
return _mapper.Map<IEnumerable<JumpResp>>(result);
|
||||||
}
|
}
|
||||||
@@ -55,7 +56,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
value.JumpTypeId,
|
value.JumpTypeId,
|
||||||
value.GearId,
|
value.GearId,
|
||||||
_mapper.Map<Jump>(value),
|
_mapper.Map<Jump>(value),
|
||||||
null /* Provenant du token */);
|
ConnectedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT: api/Jump/5
|
// PUT: api/Jump/5
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class JumpTypeController : ControllerBase
|
public class JumpTypeController : Base
|
||||||
{
|
{
|
||||||
public JumpTypeController(IJumpTypeService jumpTypeService,
|
public JumpTypeController(IJumpTypeService jumpTypeService,
|
||||||
IMapper mapper)
|
IMapper mapper)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class StatsController : ControllerBase
|
public class StatsController : Base
|
||||||
{
|
{
|
||||||
public StatsController(IStatsService statsService,
|
public StatsController(IStatsService statsService,
|
||||||
IMapper mapper)
|
IMapper mapper)
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ namespace skydiveLogs_api
|
|||||||
var iocService = new IocService(services, Configuration);
|
var iocService = new IocService(services, Configuration);
|
||||||
iocService.Configure();
|
iocService.Configure();
|
||||||
|
|
||||||
|
// AutoMapper
|
||||||
services.AddAutoMapper(typeof(Mapper.ModelProfile));
|
services.AddAutoMapper(typeof(Mapper.ModelProfile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"JWT": {
|
"JWT": {
|
||||||
"Issuer": "NoIdea",
|
"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": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"JWT": {
|
"JWT": {
|
||||||
"Issuer": "NoIdea",
|
"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": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"JWT": {
|
"JWT": {
|
||||||
"Issuer": "NoIdea",
|
"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": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
|
|||||||
Reference in New Issue
Block a user