Files
KJD/Store.Framework/Services/CurrentUserService.cs
T
2026-09-11 19:11:12 +08:00

38 lines
939 B
C#

using MAX.Core.DependencyInjection;
using MediatR;
using Store.Framework.Inerterfaces;
using Store.Framework.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Store.Framework.Services;
public record UserNotification(UserInfo user) : INotification;
/// <summary>
/// 当前用户
/// </summary>
internal class CurrentUserService : ICurrentUser, ISingletonDependency, INotificationHandler<UserNotification>
{
public string UserName => User?.UserName;
public int GroupId => User.GroupId;
public UserInfo User { get; private set; }
public bool IsSuperAdmin => User.IsSa;
public bool IsAuthorized(string code)
{
return User.UserAuthority.Contains(code);
}
Task INotificationHandler<UserNotification>.Handle(UserNotification notification, CancellationToken cancellationToken)
{
User = notification.user;
return Task.CompletedTask;
}
}