49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Learn.Archives.Core.Common
|
|
{
|
|
public static class LiveUserInfoExpand
|
|
{
|
|
|
|
/// <summary>
|
|
/// 添加 当前作用域登录用户信息
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
public static void AddLiveUserInfoExpand(this IServiceCollection services)
|
|
{
|
|
services.AddScoped<LiveUserInfo>();
|
|
}
|
|
}
|
|
public class LiveUserInfo
|
|
{
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
public LiveUserInfo(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 管理员角色id
|
|
/// </summary>
|
|
public long? RoleId
|
|
{
|
|
get => long.Parse(_httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Role)?.Value ?? "0");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 管理员id
|
|
/// </summary>
|
|
public long Id
|
|
{
|
|
get => long.Parse(_httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Id)?.Value ?? "0");
|
|
}
|
|
}
|
|
}
|