using System.Collections.Generic; using System.Linq; using FAuth.DataBase; using FAuth.Extensions.Decryptor; namespace FAuth.Extensions.Account { /// /// 账号帮助类 /// public class AccountHelper { /// /// 数据库上下文 /// public FAuthDb Db { get; set; } /// /// 用户凭据加密提供器 /// public IUserTicketDryptor TicketDryptor { get; set; } public AccountHelper(FAuthDb db,IUserTicketDryptor ticketDryptor) { this.Db = db; this.TicketDryptor = ticketDryptor; } /// /// 查询用户是否为FAuth系统管理员 /// /// 用户编号 /// 是否为FAuth系统管理员 public bool IsSystemAdmin(int userId) { var qu = from arg in this.Db.App_RoleGroups join rgr in this.Db.RoleGroup_Roles on arg.RoleGroupId equals rgr.RoleGroupId join ru in this.Db.Role_Users on rgr.RoleId equals ru.RoleId where arg.AppId == 1 && arg.RoleGroupId == 1 && ru.UserId == userId select 1; return qu.Any(); } /// /// 用户是否不是系统管理员 /// /// 用户编号 /// 是否不是管理员 public bool IsNotSystemAdmin(int userId) => !IsSystemAdmin(userId); /// /// 查询票据是否为系统管理员 /// /// 用户票据 /// 是管理员True,否则false public bool IsSystemAdmin(string userTicket) => IsSystemAdmin(this.TicketDryptor.Decrypt(userTicket).Id); /// /// 查询票据是否不是系统管理员 /// /// 用户票据 /// 是管理员False,否则True public bool IsNotSystemAdmin(string userTicket) => !IsSystemAdmin(userTicket); } }