mirror of https://github.com/abpframework/abp.git
13 changed files with 211 additions and 5 deletions
@ -0,0 +1,82 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.Users |
||||
|
{ |
||||
|
public class CmsUser : AggregateRoot<Guid>, IUser, IUpdateUserData |
||||
|
{ |
||||
|
public virtual Guid? TenantId { get; protected set; } |
||||
|
|
||||
|
public virtual string UserName { get; protected set; } |
||||
|
|
||||
|
public virtual string Email { get; protected set; } |
||||
|
|
||||
|
public virtual string Name { get; set; } |
||||
|
|
||||
|
public virtual string Surname { get; set; } |
||||
|
|
||||
|
public virtual bool EmailConfirmed { get; protected set; } |
||||
|
|
||||
|
public virtual string PhoneNumber { get; protected set; } |
||||
|
|
||||
|
public virtual bool PhoneNumberConfirmed { get; protected set; } |
||||
|
|
||||
|
protected CmsUser() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public CmsUser(IUserData user) |
||||
|
: base(user.Id) |
||||
|
{ |
||||
|
TenantId = user.TenantId; |
||||
|
UpdateInternal(user); |
||||
|
} |
||||
|
|
||||
|
public virtual bool Update(IUserData user) |
||||
|
{ |
||||
|
if (Id != user.Id) |
||||
|
{ |
||||
|
throw new ArgumentException($"Given User's Id '{user.Id}' does not match to this User's Id '{Id}'"); |
||||
|
} |
||||
|
|
||||
|
if (TenantId != user.TenantId) |
||||
|
{ |
||||
|
throw new ArgumentException($"Given User's TenantId '{user.TenantId}' does not match to this User's TenantId '{TenantId}'"); |
||||
|
} |
||||
|
|
||||
|
if (Equals(user)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
UpdateInternal(user); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
protected virtual bool Equals(IUserData user) |
||||
|
{ |
||||
|
return Id == user.Id && |
||||
|
TenantId == user.TenantId && |
||||
|
UserName == user.UserName && |
||||
|
Name == user.Name && |
||||
|
Surname == user.Surname && |
||||
|
Email == user.Email && |
||||
|
EmailConfirmed == user.EmailConfirmed && |
||||
|
PhoneNumber == user.PhoneNumber && |
||||
|
PhoneNumberConfirmed == user.PhoneNumberConfirmed; |
||||
|
} |
||||
|
|
||||
|
protected virtual void UpdateInternal(IUserData user) |
||||
|
{ |
||||
|
Email = user.Email; |
||||
|
Name = user.Name; |
||||
|
Surname = user.Surname; |
||||
|
EmailConfirmed = user.EmailConfirmed; |
||||
|
PhoneNumber = user.PhoneNumber; |
||||
|
PhoneNumberConfirmed = user.PhoneNumberConfirmed; |
||||
|
UserName = user.UserName; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using Volo.Abp.Uow; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.Users |
||||
|
{ |
||||
|
public class CmsUserLookupService: UserLookupService<CmsUser, ICmsUserRepository>, ICmsUserLookupService |
||||
|
{ |
||||
|
public CmsUserLookupService( |
||||
|
ICmsUserRepository userRepository, |
||||
|
IUnitOfWorkManager unitOfWorkManager) |
||||
|
: base( |
||||
|
userRepository, |
||||
|
unitOfWorkManager) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
protected override CmsUser CreateUser(IUserData externalUser) |
||||
|
{ |
||||
|
return new CmsUser(externalUser); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
||||
|
using Volo.Abp.EventBus.Distributed; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.Users |
||||
|
{ |
||||
|
public class CmsUserSynchronizer : |
||||
|
IDistributedEventHandler<EntityUpdatedEto<UserEto>>, |
||||
|
ITransientDependency |
||||
|
{ |
||||
|
protected ICmsUserRepository UserRepository { get; } |
||||
|
|
||||
|
protected ICmsUserLookupService UserLookupService { get; } |
||||
|
|
||||
|
public CmsUserSynchronizer( |
||||
|
ICmsUserRepository userRepository, |
||||
|
ICmsUserLookupService userLookupService) |
||||
|
{ |
||||
|
UserRepository = userRepository; |
||||
|
UserLookupService = userLookupService; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task HandleEventAsync(EntityUpdatedEto<UserEto> eventData) |
||||
|
{ |
||||
|
var user = await UserRepository.FindAsync(eventData.Entity.Id); |
||||
|
if (user == null) |
||||
|
{ |
||||
|
user = await UserLookupService.FindByIdAsync(eventData.Entity.Id); |
||||
|
if (user == null) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (user.Update(eventData.Entity)) |
||||
|
{ |
||||
|
await UserRepository.UpdateAsync(user); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.Users |
||||
|
{ |
||||
|
public interface ICmsUserLookupService : IUserLookupService<CmsUser> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.Users |
||||
|
{ |
||||
|
public interface ICmsUserRepository: IUserRepository<CmsUser> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Users.EntityFrameworkCore; |
||||
|
using Volo.CmsKit.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.CmsKit.Users |
||||
|
{ |
||||
|
public class EfCoreCmsUserRepository: EfCoreUserRepositoryBase<ICmsKitDbContext, CmsUser>, ICmsUserRepository |
||||
|
{ |
||||
|
public EfCoreCmsUserRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue