71 lines
1.9 KiB
C#
71 lines
1.9 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>
|
|
/// 是超管?
|
|
/// </summary>
|
|
public bool IsSa
|
|
{
|
|
get => RoleId == 1;
|
|
}
|
|
/// <summary>
|
|
/// 管理员id
|
|
/// </summary>
|
|
public long Id
|
|
{
|
|
get => long.Parse(_httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Id)?.Value ?? "0");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 管理员id
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Name)?.Value??string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scope
|
|
/// </summary>
|
|
public string Scope
|
|
{
|
|
get => _httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Scope)?.Value ?? string.Empty;
|
|
}
|
|
}
|
|
}
|