Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #27

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public override void ConfigureServices(ServiceConfigurationContext context)
ConfigureCachingServices(context.Services);

ConfigureBusServices(context.Services);

context.Services.AddHostedService<UserInitializeService>();
}

private void ConfigureCachingServices(IServiceCollection services)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,40 @@ namespace Nerosoft.Starfish.Application;
/// <summary>
/// 创建用户命令
/// </summary>
public sealed class UserCreateCommand : Command<UserCreateDto>
public sealed class UserCreateCommand : Command
{
/// <summary>
/// 构造函数
/// 用户名
/// </summary>
/// <param name="data">用户创建数据传输对象</param>
public UserCreateCommand(UserCreateDto data)
: base(data)
{
}
public string UserName { get; set; }

/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }

/// <summary>
/// 邮箱
/// </summary>
public string Email { get; set; }

/// <summary>
/// 电话
/// </summary>
public string Phone { get; set; }

/// <summary>
/// 昵称
/// </summary>
public string NickName { get; set; }

/// <summary>
/// 是否是管理员
/// </summary>
public bool IsAdmin { get; set; } = false;

/// <summary>
/// 是否是预留账号
/// </summary>
public bool Reserved { get; set; } = false;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ public interface IUserApplicationService : IApplicationService
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task ResetPasswordAsync(string id, string password, CancellationToken cancellationToken = default);

/// <summary>
/// 初始化用户
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task InitializeAsync(CancellationToken cancellationToken = default);
}

This file was deleted.

16 changes: 11 additions & 5 deletions Source/Starfish.Service/Application/Handlers/UserCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public Task HandleAsync(UserCreateCommand message, MessageContext context, Cance
return ExecuteAsync(async () =>
{
var business = await Factory.CreateAsync<UserGeneralBusiness>(cancellationToken);
business.UserName = message.Item1.UserName;
business.Password = message.Item1.Password;
business.NickName = message.Item1.NickName;
business.Email = message.Item1.Email;
business.Phone = message.Item1.Phone;
business.UserName = message.UserName;
business.Password = message.Password;
business.NickName = message.NickName;
business.Email = message.Email;
business.Phone = message.Phone;
business.IsAdmin = message.IsAdmin;
business.Reserved = message.Reserved;
business.MarkAsInsert();
await business.SaveAsync(false, cancellationToken);

Expand All @@ -52,7 +54,11 @@ public Task HandleAsync(UserUpdateCommand message, MessageContext context, Cance

business.Email = message.Item2.Email;
business.NickName = message.Item2.NickName;
business.Phone = message.Item2.Phone;
business.IsAdmin = message.Item2.IsAdmin;

business.MarkAsUpdate();

await business.SaveAsync(true, cancellationToken);
});
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,11 @@ public Task ResetPasswordAsync(string id, string password, CancellationToken can
var input = new ResetPasswordInput(id, password);
return useCase.ExecuteAsync(input, cancellationToken);
}

public Task InitializeAsync(CancellationToken cancellationToken = default)
{
var useCase = LazyServiceProvider.GetService<IUserInitializeUseCase>();
return useCase.ExecuteAsync(cancellationToken);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public IdentityMappingProfile()
.ForMember(dest => dest.NickName, options => options.MapFrom(src => src.User.NickName))
.ForMember(dest => dest.Email, options => options.MapFrom(src => src.User.Email))
.ForMember(dest => dest.Phone, options => options.MapFrom(src => src.User.Phone));

CreateMap<Administrator, AdministratorItemDto>();
CreateMap<AdministratorAssignDto, AdministratorAssignCommand>();
}

private static string Mask(string source)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Nerosoft.Starfish.Application;

internal class UserInitializeService : BackgroundService
{
private readonly IUserApplicationService _service;
private readonly ILogger<UserInitializeService> _logger;

public UserInitializeService(IUserApplicationService service, ILoggerFactory logger)
{
_service = service;
_logger = logger.CreateLogger<UserInitializeService>();
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
await _service.InitializeAsync(stoppingToken);
}
catch (Exception exception)
{
_logger.LogError(exception, exception.Message);
}
}
}
12 changes: 0 additions & 12 deletions Source/Starfish.Service/Domain/Aggregates/Administrator.cs

This file was deleted.

22 changes: 21 additions & 1 deletion Source/Starfish.Service/Domain/Aggregates/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class User : Aggregate<string>, IHasCreateTime, IHasUpdateTime, IT
private User()
{
}

/// <summary>
/// 初始化用户聚合根
/// </summary>
Expand Down Expand Up @@ -77,6 +77,11 @@ private User(string userName, string passwordHash, string passwordSalt)
/// <remarks>预留账号不允许删除、设置角色等</remarks>
public bool Reserved { get; set; }

/// <summary>
/// 是否是管理员
/// </summary>
public bool IsAdmin { get; set; }

/// <summary>
/// 来源
/// </summary>
Expand Down Expand Up @@ -155,6 +160,21 @@ internal void SetNickName(string nickName)
NickName = nickName;
}

internal void SetIsAdmin(bool isAdmin)
{
if (Reserved)
{
return;
}

if (isAdmin == IsAdmin)
{
return;
}

IsAdmin = isAdmin;
}

/// <summary>
/// 增加授权失败次数
/// </summary>
Expand Down
Loading
Loading