forked from ddrilling/AsbCloudServer
Added IdUser claim to authenticated user claims
This commit is contained in:
parent
b1495dda34
commit
d6bf5d3252
@ -27,6 +27,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
private static readonly TimeSpan expiresTimespan = TimeSpan.FromDays(365.25);
|
||||
private static readonly Encoding encoding = Encoding.UTF8;
|
||||
private const int PasswordSaltLength = 5;
|
||||
private const string claimIdUser = "id";
|
||||
private const string claimNameidCompany = "idCompany";
|
||||
private readonly HashAlgorithm hashAlgoritm;
|
||||
private readonly Random rnd;
|
||||
@ -157,6 +158,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim(claimIdUser, user.Id.ToString()),
|
||||
new Claim(ClaimsIdentity.DefaultNameClaimType, user.Login),
|
||||
new Claim(ClaimsIdentity.DefaultRoleClaimType, user.Role?.Caption??"GUEST"),
|
||||
new Claim(claimNameidCompany, user.IdCompany.ToString()),
|
||||
|
@ -37,11 +37,12 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> SaveFilesAsync(int idWell, int idCategory,
|
||||
int idUser, [FromForm] IFormFileCollection files, CancellationToken token = default)
|
||||
[FromForm] IFormFileCollection files, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
int? idUser = User.GetUserId();
|
||||
|
||||
if (idCompany is null)
|
||||
if (idCompany is null || idUser is null)
|
||||
return Forbid();
|
||||
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
@ -49,7 +50,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
return Forbid();
|
||||
|
||||
var fileInfoCollection = files.Select(f =>
|
||||
(f.FileName, idWell, idCategory, DateTime.Now, idUser));
|
||||
(f.FileName, idWell, idCategory, DateTime.Now, (int)idUser));
|
||||
|
||||
var fileNamesAndIds = fileService.SaveFilesPropertiesToDb(idWell,
|
||||
idCategory, fileInfoCollection);
|
||||
|
@ -15,5 +15,16 @@ namespace AsbCloudWebApi
|
||||
? uid
|
||||
: null;
|
||||
}
|
||||
|
||||
public static int? GetUserId(this ClaimsPrincipal user)
|
||||
{
|
||||
var userId = user.FindFirst(nameof(User.Id));
|
||||
if (userId is null)
|
||||
return null;
|
||||
|
||||
return int.TryParse(userId.Value, out int uid)
|
||||
? uid
|
||||
: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user