feat: 用户account领域与user领域关系

This commit is contained in:
陈淳
2024-04-29 14:22:45 +08:00
parent df5224cf12
commit cabdd55cf5
4 changed files with 99 additions and 87 deletions

View File

@@ -203,18 +203,6 @@ namespace Yi.Framework.Rbac.Application.Services
throw new UserFriendlyException("验证码错误");
}
private void ValidateUserName(RegisterDto input)
{
// 正则表达式,匹配只包含数字和字母的字符串
string pattern = @"^[a-zA-Z0-9]+$";
bool isMatch = Regex.IsMatch(input.UserName, pattern);
if (!isMatch)
{
throw new UserFriendlyException("用户名不能包含除【字母】与【数字】的其他字符");
}
}
/// <summary>
/// 注册,需要验证码通过
/// </summary>
@@ -228,28 +216,9 @@ namespace Yi.Framework.Rbac.Application.Services
{
throw new UserFriendlyException("该系统暂未开放注册功能");
}
if (input.UserName == UserConst.Admin)
{
throw new UserFriendlyException("用户名无效注册!");
}
if (input.UserName.Length < 2)
{
throw new UserFriendlyException("账号名需大于等于2位");
}
if (input.Password.Length < 6)
{
throw new UserFriendlyException("密码需大于等于6位");
}
//校验用户名
ValidateUserName(input);
//校验验证码,根据电话号码获取 value比对验证码已经uuid
await ValidationPhoneCaptchaAsync(input);
//注册领域逻辑
await _accountManager.RegisterAsync(input.UserName, input.Password, input.Phone);
}

View File

@@ -24,7 +24,7 @@ namespace Yi.Framework.Rbac.Application.Services.System
/// <summary>
/// User服务实现
/// </summary>
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>,IUserService
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>, IUserService
//IUserService
{
public UserService(ISqlSugarRepository<UserEntity, Guid> repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus, IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> userCache) : base(repository)
@@ -82,7 +82,7 @@ namespace Yi.Framework.Rbac.Application.Services.System
protected override UserEntity MapToEntity(UserCreateInputVo createInput)
{
var output= base.MapToEntity(createInput);
var output = base.MapToEntity(createInput);
output.EncryPassword = new Domain.Entities.ValueObjects.EncryPasswordValueObject(createInput.Password);
return output;
}
@@ -96,37 +96,24 @@ namespace Yi.Framework.Rbac.Application.Services.System
[Permission("system:user:add")]
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
{
if (input.UserName == UserConst.Admin || input.UserName == UserConst.TenantAdmin)
{
throw new UserFriendlyException(UserConst.Name_Not_Allowed);
}
if (string.IsNullOrEmpty(input.Password))
{
throw new UserFriendlyException(UserConst.Login_Passworld_Error);
}
if (await _repository.IsAnyAsync(u => input.UserName.Equals(u.UserName)))
{
throw new UserFriendlyException(UserConst.User_Exist);
}
var entitiy = await MapToEntityAsync(input);
entitiy.BuildPassword();
//using (var uow = _unitOfWorkManager.CreateContext())
//{
var returnEntity = await _repository.InsertReturnEntityAsync(entitiy);
await _userManager.GiveUserSetRoleAsync(new List<Guid> { returnEntity.Id }, input.RoleIds);
await _userManager.GiveUserSetPostAsync(new List<Guid> { returnEntity.Id }, input.PostIds);
//uow.Commit();
await _userManager.CreateAsync(entitiy);
await _userManager.GiveUserSetRoleAsync(new List<Guid> { entitiy.Id }, input.RoleIds);
await _userManager.GiveUserSetPostAsync(new List<Guid> { entitiy.Id }, input.PostIds);
var result = await MapToGetOutputDtoAsync(returnEntity);
await _localEventBus.PublishAsync(new UserCreateEventArgs(returnEntity.Id));
var result = await MapToGetOutputDtoAsync(entitiy);
return result;
//}
}
protected override async Task<UserEntity> MapToEntityAsync(UserCreateInputVo createInput)
{
var entitiy = await base.MapToEntityAsync(createInput);
entitiy.BuildPassword();
return entitiy;
}
/// <summary>
/// 单查
/// </summary>