You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB
C#

using NPin.Framework.Upms.Domain.Shared.Consts;
using Volo.Abp.Users;
namespace NPin.Framework.Upms.Domain.Extensions;
public static class CurrentUserExtensions
{
/// <summary>
/// 获取用户权限代码列表
/// </summary>
/// <param name="currentUser"></param>
/// <returns></returns>
public static List<string> GetPermissions(this ICurrentUser currentUser)
{
return currentUser.FindClaims(TokenTypeConst.Permission)
.Select(x => x.Value)
.ToList();
}
/// <summary>
/// 获取用户组织机构ID列表
/// </summary>
/// <param name="currentUser"></param>
/// <returns></returns>
public static List<Guid> GetOrganizationIds(this ICurrentUser currentUser)
{
return currentUser.FindClaims(TokenTypeConst.Organizations)
.Select(x => Guid.Parse(x.Value))
.ToList();
}
/// <summary>
/// 用户是否是通过Refresh进来的
/// </summary>
/// <param name="currentUser"></param>
/// <returns></returns>
public static bool IsRefreshToken(this ICurrentUser currentUser)
{
var valOrNull = currentUser.FindClaim(TokenTypeConst.Refresh)?.Value;
return valOrNull is not null && bool.Parse(valOrNull);
}
}