Yuebon.NetCore/Yuebon.AspNetCore/Common/Permission.cs
(完整代码) 1KBnamespace Yuebon.AspNetCore.Common
{
/// <summary>
/// 权限控制
/// </summary>
public static class Permission
{
/// <summary>
/// 判断当前用户是否拥有某功能点的权限
/// </summary>
/// <param name="functionCode">功能编码code</param>
/// <param name="userId">用户id</param>
/// <returns></returns>
public static bool HasFunction(string functionCode, string userId)
{
bool hasFunction = false;
if (!string.IsNullOrEmpty(userId)) {
if (string.IsNullOrEmpty(functionCode))
{
hasFunction = true;
}
else
{
List<UserVisitMenus> listFunction =new YuebonCacheHelper().Get("User_Function_" + userId).ToJson().ToList<UserVisitMenus>();
if (listFunction != null && listFunction.Count(t => t.EnCode == functionCode) > 0)
{
hasFunction = true;
}
}
}
return hasFunction;
}
/// <summary>
/// 判断是否为系统管理员或超级管理员
/// </summary>
/// <returns>true:系统管理员或超级管理员,false:不是系统管理员或超级管理员</returns>
/// <param name="currentUser"></param>
/// <returns></returns>
public static bool IsAdmin(YuebonCurrentUser currentUser)
{
bool blnIsAdmin = false;
if (currentUser != null)
{
if(currentUser.Account == "admin"|| currentUser.Role.Contains("administrators",StringComparison.Ordinal))
{
return true;
}
}
return blnIsAdmin;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。