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]")]
|
||||
[ApiController]
|
||||
public class AircraftController : ControllerBase
|
||||
public class AircraftController : Base
|
||||
{
|
||||
public AircraftController(IAircraftService aircraftService,
|
||||
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]")]
|
||||
[ApiController]
|
||||
public class DropZoneController : ControllerBase
|
||||
public class DropZoneController : Base
|
||||
{
|
||||
public DropZoneController(IDropZoneService dropZoneService,
|
||||
IMapper mapper)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<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);
|
||||
}
|
||||
@@ -55,7 +56,7 @@ namespace skydiveLogs_api.Controllers
|
||||
value.JumpTypeId,
|
||||
value.GearId,
|
||||
_mapper.Map<Jump>(value),
|
||||
null /* Provenant du token */);
|
||||
ConnectedUser);
|
||||
}
|
||||
|
||||
// PUT: api/Jump/5
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -67,6 +67,7 @@ namespace skydiveLogs_api
|
||||
var iocService = new IocService(services, Configuration);
|
||||
iocService.Configure();
|
||||
|
||||
// AutoMapper
|
||||
services.AddAutoMapper(typeof(Mapper.ModelProfile));
|
||||
}
|
||||
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user