Files
Yi.Admin/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Event/LoginEventHandler.cs

37 lines
1.2 KiB
C#
Raw Normal View History

2023-04-13 21:12:06 +08:00
using Furion.EventBus;
using IPTools.Core;
using UAParser;
using Yi.Framework.Infrastructure.AspNetCore;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Infrastructure.Helper;
2023-04-15 17:33:42 +08:00
using Yi.Furion.Core.Rbac.Entities;
using Yi.Furion.Core.Rbac.Etos;
2023-04-13 21:12:06 +08:00
2023-04-15 17:33:42 +08:00
namespace Yi.Furion.Application.Rbac.Event
2023-04-13 21:12:06 +08:00
{
2023-04-15 22:44:33 +08:00
public class LoginEventHandler : IEventSubscriber,ISingleton
2023-04-13 21:12:06 +08:00
{
private readonly IRepository<LoginLogEntity> _loginLogRepository;
2023-04-15 22:44:33 +08:00
public LoginEventHandler(IRepository<LoginLogEntity> loginLogRepository)
2023-04-13 21:12:06 +08:00
{
_loginLogRepository = loginLogRepository;
}
2023-04-19 18:06:40 +08:00
[EventSubscribe(nameof(LoginEventSource))]
2023-04-13 21:12:06 +08:00
public Task HandlerAsync(EventHandlerExecutingContext context)
{
2023-04-15 17:33:42 +08:00
var eventData = (LoginEventArgs)context.Source.Payload;
2023-04-19 18:06:40 +08:00
var loginLogEntity = eventData.LoginLogEntity;
2023-04-13 21:12:06 +08:00
loginLogEntity.Id = SnowflakeHelper.NextId;
loginLogEntity.LogMsg = eventData.UserName + "登录系统";
loginLogEntity.LoginUser = eventData.UserName;
_loginLogRepository.InsertAsync(loginLogEntity);
return Task.CompletedTask;
}
2023-04-19 18:06:40 +08:00
2023-04-13 21:12:06 +08:00
}
}