32 lines
819 B
C#
32 lines
819 B
C#
using System;
|
|
using HN.Application;
|
|
using HN.Infrastructure.Identity;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
namespace Website
|
|
{
|
|
public sealed class HttpExecutingUserProvider : IExecutingUserProvider
|
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly UserManager<User> _userManager;
|
|
|
|
public HttpExecutingUserProvider(IHttpContextAccessor httpContextAccessor, UserManager<User> userManager)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
public Guid GetCurrentUserId()
|
|
{
|
|
var uid = _userManager.GetUserId(_httpContextAccessor.HttpContext.User);
|
|
|
|
if (!Guid.TryParse(uid, out Guid result))
|
|
{
|
|
throw new UserNotConnected();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |