38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using CloudBuilder.Core.DependencyInjection.EventBuses;
|
|
using CloudBuilder.Security.Entity;
|
|
using CloudBuilder.Security.Policy;
|
|
using CloudBuilder.Security.Subscriber;
|
|
|
|
namespace CloudBuilder.Security.Service.Subscriber
|
|
{
|
|
public class InsertSecurityUserActorSubscriber : ISecurityUserRegisterSubscriber
|
|
{
|
|
private readonly IApplicationService service;
|
|
|
|
public InsertSecurityUserActorSubscriber(IApplicationService service)
|
|
{
|
|
this.service = service;
|
|
}
|
|
|
|
public void Handle(EventData eventData)
|
|
{
|
|
IRepository<SecurityUserActorEntity> repository = service.GetRepository<IRepository<SecurityUserActorEntity>>();
|
|
|
|
SecurityUserActorEntity ent = new SecurityUserActorEntity();
|
|
ent.UserName = ((SecurityUserEntity)eventData.EventSource).UserName;
|
|
ent.ActorName = SecurityUserPolicy.SECURITY_USER_BASE_ACTOR;
|
|
repository.InsertNow(ent);
|
|
|
|
//第一个注册用户就是管理员
|
|
if (ent.UserName == SecurityPrefixPolicy.SECURITY_USER_FORMAT.Substring(0, SecurityPrefixPolicy.SECURITY_USER_FORMAT.Length - 1) + "1")
|
|
{
|
|
ent = new SecurityUserActorEntity();
|
|
ent.UserName = ((SecurityUserEntity)eventData.EventSource).UserName;
|
|
ent.ActorName = SecurityUserPolicy.SYSTEM_ACTOR;
|
|
repository.InsertNow(ent);
|
|
}
|
|
}
|
|
}
|
|
}
|