update:修改项目名称从Dilon到Ewide
This commit is contained in:
16
Api/Ewide.Core/Manager/IUserManager.cs
Normal file
16
Api/Ewide.Core/Manager/IUserManager.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
public interface IUserManager
|
||||
{
|
||||
string Account { get; }
|
||||
string Name { get; }
|
||||
bool SuperAdmin { get; }
|
||||
SysUser User { get; }
|
||||
string UserId { get; }
|
||||
|
||||
Task<SysUser> CheckUserAsync(string userId, bool tracking = true);
|
||||
Task<SysEmp> GetUserEmpInfo(string userId);
|
||||
}
|
||||
}
|
||||
75
Api/Ewide.Core/Manager/UserManager.cs
Normal file
75
Api/Ewide.Core/Manager/UserManager.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户管理
|
||||
/// </summary>
|
||||
public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
private readonly IRepository<SysUser> _sysUserRep; // 用户表仓储
|
||||
private readonly IRepository<SysEmp> _sysEmpRep; // 员工表
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public string UserId
|
||||
{
|
||||
get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
|
||||
}
|
||||
|
||||
public string Account
|
||||
{
|
||||
get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.CLAINM_ACCOUNT)?.Value;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.CLAINM_NAME)?.Value;
|
||||
}
|
||||
|
||||
public bool SuperAdmin
|
||||
{
|
||||
get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.CLAINM_SUPERADMIN)?.Value == ((int)AdminType.SuperAdmin).ToString();
|
||||
}
|
||||
|
||||
public SysUser User
|
||||
{
|
||||
get => _sysUserRep.Find(UserId);
|
||||
}
|
||||
|
||||
public UserManager(IRepository<SysUser> sysUserRep,
|
||||
IRepository<SysEmp> sysEmpRep,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_sysUserRep = sysUserRep;
|
||||
_sysEmpRep = sysEmpRep;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="tracking"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SysUser> CheckUserAsync(string userId, bool tracking = true)
|
||||
{
|
||||
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == userId, tracking);
|
||||
return user ?? throw Oops.Oh(ErrorCode.D1002);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户员工信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SysEmp> GetUserEmpInfo(string userId)
|
||||
{
|
||||
var emp = await _sysEmpRep.FirstOrDefaultAsync(u => u.Id == userId, false);
|
||||
return emp ?? throw Oops.Oh(ErrorCode.D1002);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user