Skip to content

Commit

Permalink
Merge pull request #32 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Codespilot authored May 9, 2024
2 parents 9f8d312 + 521f8a5 commit 411e0b4
Show file tree
Hide file tree
Showing 34 changed files with 557 additions and 319 deletions.
52 changes: 26 additions & 26 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<EnablePackageVersionOverride>true</EnablePackageVersionOverride>
<EuoniaPackageVersion>8.1.23</EuoniaPackageVersion>
<EuoniaPackageVersion>8.1.24</EuoniaPackageVersion>
<FluentBlazorPackageVersion>4.7.2</FluentBlazorPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageVersion Include="BlazorMonaco" Version="3.2.0" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageVersion Include="Dapper" Version="2.1.28" />
<PackageVersion Include="Dapper" Version="2.1.44" />
<PackageVersion Include="Dapper.Contrib" Version="2.0.78" />
<PackageVersion Include="Dapper.SqlBuilder" Version="2.0.78" />
<PackageVersion Include="Euonia.Application" Version="$(EuoniaPackageVersion)" />
Expand All @@ -29,38 +30,37 @@
<PackageVersion Include="Euonia.Pipeline" Version="$(EuoniaPackageVersion)" />
<PackageVersion Include="Euonia.Validation" Version="$(EuoniaPackageVersion)" />
<PackageVersion Include="Euonia.Repository.EfCore" Version="$(EuoniaPackageVersion)" />
<PackageVersion Include="Google.Api.CommonProtos" Version="2.14.0" />
<PackageVersion Include="Google.Protobuf" Version="3.25.3" />
<PackageVersion Include="Grpc.Net.Client" Version="2.61.0" />
<PackageVersion Include="Grpc.Tools" Version="2.62.0" />
<PackageVersion Include="IdentityModel" Version="6.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageVersion Include="Google.Api.CommonProtos" Version="2.15.0" />
<PackageVersion Include="Google.Protobuf" Version="3.26.1" />
<PackageVersion Include="Grpc.Net.Client" Version="2.62.0" />
<PackageVersion Include="Grpc.Tools" Version="2.63.0" />
<PackageVersion Include="IdentityModel" Version="7.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="3.1.1" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.4.1" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Emoji" Version="4.4.0" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.4.0" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="3.2.0" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="$(FluentBlazorPackageVersion)" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="$(FluentBlazorPackageVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.11" />
<PackageVersion Include="Refit" Version="7.0.0" />
<PackageVersion Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageVersion Include="Refit.Newtonsoft.Json" Version="7.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.20" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.33" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="7.0.0-preview.1" />
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2">
Expand All @@ -72,7 +72,7 @@
</PackageVersion>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageVersion Include="System.Text.Json" Version="8.0.2" />
<PackageVersion Include="System.Text.Json" Version="8.0.3" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFrameworkVersion.Equals('v5.0')) ">
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
Expand Down Expand Up @@ -108,7 +108,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="coverlet.collector" Version="6.0.1">
<PackageVersion Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
Expand Down
2 changes: 1 addition & 1 deletion Documents/SCRIPTS_MSSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE [operate_log] (
[Id] bigint NOT NULL,
[Module] varchar(20) NOT NULL,
[Type] varchar(50) NOT NULL,
[Description] varchar(2000) NULL,
[Content] varchar(2000) NULL,
[UserName] varchar(64) NULL,
[OperateTime] datetime DEFAULT getdate() NOT NULL,
[Error] varchar(2000) NULL,
Expand Down
2 changes: 1 addition & 1 deletion Documents/SCRIPTS_MYSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE `operate_log` (
`Id` bigint NOT NULL,
`Module` varchar(20) NOT NULL,
`Type` varchar(50) NOT NULL,
`Description` varchar(2000) NULL DEFAULT NULL,
`Content` varchar(2000) NULL DEFAULT NULL,
`UserName` varchar(64) NULL DEFAULT NULL,
`OperateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`Error` varchar(2000) NULL DEFAULT NULL,
Expand Down
8 changes: 4 additions & 4 deletions Documents/SCRIPTS_PGSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE "public"."operate_log" (
"Id" int8 NOT NULL,
"Module" varchar(20) COLLATE "pg_catalog"."default" NOT NULL,
"Type" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"Description" varchar(2000) COLLATE "pg_catalog"."default",
"Content" varchar(2000) COLLATE "pg_catalog"."default",
"UserName" varchar(255) COLLATE "pg_catalog"."default",
"OperateTime" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"Error" varchar(2000) COLLATE "pg_catalog"."default",
Expand Down Expand Up @@ -86,10 +86,10 @@ CREATE TABLE "public"."configuration_item" (
;

CREATE INDEX "IDX_CONFIG_ITEM_FK" ON "public"."configuration_item" USING btree (
"ConfigurationId" "pg_catalog"."int8_ops" ASC NULLS LAST
"ConfigurationId" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE UNIQUE INDEX "IDX_CONFIG_ITEM_UNIQUE" ON "public"."configuration_item" USING btree (
"ConfigurationId" "pg_catalog"."int8_ops" ASC NULLS LAST,
"ConfigurationId" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
"Key" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
```
Expand All @@ -110,7 +110,7 @@ CREATE TABLE "public"."configuration_revision" (
;

CREATE INDEX "IDS_CONFIG_REVISION_FK" ON "public"."configuration_revision" USING btree (
"ConfigurationId" "pg_catalog"."int8_ops" ASC NULLS LAST
"ConfigurationId" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
```

Expand Down
2 changes: 1 addition & 1 deletion Documents/SCRIPTS_SQLITE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE "operate_log" (
"Id" integer NOT NULL,
"Module" text NOT NULL,
"Type" text NOT NULL,
"Description" text,
"Content" text,
"UserName" text,
"OperateTime" text NOT NULL,
"Error" text,
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Overview/概览 ⚡

[![Build Status](https://img.shields.io/github/actions/workflow/status/NerosoftDev/Starfish/dotnet.yml)]()
[![Build Status](https://img.shields.io/github/actions/workflow/status/NerosoftDev/Starfish/dotnet.yml)](https://github.com/NerosoftDev/Starfish/actions)
[![License](https://img.shields.io/badge/license-AGPL--3.0-blue.svg)](LICENSE)
[![GitHub release](https://img.shields.io/github/release/NerosoftDev/Starfish.svg)]()
[![GitHub stars](https://img.shields.io/github/stars/NerosoftDev/Starfish.svg)]()
[![GitHub release](https://img.shields.io/github/release/NerosoftDev/Starfish.svg)](https://github.com/NerosoftDev/Starfish/releases)
[![GitHub stars](https://img.shields.io/github/stars/NerosoftDev/Starfish.svg)](https://github.com/NerosoftDev/Starfish/stargazers)

Starfish is a lightweight powerful distributed configuration server for .NET application.

Expand Down
1 change: 1 addition & 0 deletions Source/Starfish.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ public static class Configuration
public static class RegexPattern
{
public const string Secret = @"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,32}$";
public const string Password = @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\x00-\xff]{8,32}$";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ public ChangePasswordCommand()
{
}

public ChangePasswordCommand(string userId, string password)
public ChangePasswordCommand(string userId, string password, string actionType)
: this()
{
UserId = userId;
Password = password;
ActionType = actionType;
}

/// <summary>
Expand All @@ -27,4 +28,10 @@ public ChangePasswordCommand(string userId, string password)
/// 新密码
/// </summary>
public string Password { get; set; }

/// <summary>
/// 操作方式
/// </summary>
/// <value>change-修改;reset-重置</value>
public string ActionType { get; set; }
}
16 changes: 6 additions & 10 deletions Source/Starfish.Service/Application/Handlers/UserCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Nerosoft.Starfish.Application;
/// 用户命令处理器
/// </summary>
public sealed class UserCommandHandler : CommandHandlerBase,
IHandler<UserCreateCommand>,
IHandler<UserUpdateCommand>,
IHandler<ChangePasswordCommand>,
IHandler<UserDeleteCommand>
IHandler<UserCreateCommand>,
IHandler<UserUpdateCommand>,
IHandler<ChangePasswordCommand>,
IHandler<UserDeleteCommand>
{
/// <summary>
/// 初始化<see cref="UserCommandHandler"/>.
Expand Down Expand Up @@ -58,7 +58,7 @@ public Task HandleAsync(UserUpdateCommand message, MessageContext context, Cance
business.IsAdmin = message.Item2.IsAdmin;

business.MarkAsUpdate();

await business.SaveAsync(true, cancellationToken);
});
}
Expand All @@ -68,11 +68,7 @@ public Task HandleAsync(ChangePasswordCommand message, MessageContext context, C
{
return ExecuteAsync(async () =>
{
var business = await Factory.FetchAsync<UserGeneralBusiness>(message.UserId, cancellationToken);

business.Password = message.Password;
business.MarkAsUpdate();
await business.SaveAsync(true, cancellationToken);
_ = await Factory.ExecuteAsync<UserPasswordBusiness>(message.UserId, message.Password, message.ActionType, cancellationToken);
});
}

Expand Down
19 changes: 11 additions & 8 deletions Source/Starfish.Service/Application/Mappings/LogsMappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ internal class LogsMappingProfile : Profile
public LogsMappingProfile()
{
CreateMap<OperateLog, OperateLogDto>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => GetTypeName(src.Type)));
.ForMember(dest => dest.Description, opt => opt.MapFrom(GetDescription));
}

private static string GetTypeName(string type)
private static string GetDescription(OperateLog source, OperateLogDto destination, object obj, ResolutionContext context)
{
return type.ToLowerInvariant() switch
var key = $"IDS_LOG_MESSAGE_{source.Module}_{source.Type}".Normalize(TextCaseType.Upper).Replace(".", "_");

var value = Resources.ResourceManager.GetString(key);

if (string.IsNullOrEmpty(value))
{
"auth.password" => "密码登录",
"auth.refresh_token" => "刷新Token",
"auth.otp" => "验证码登录",
_ => type
};
return value;
}

return string.Format(value, source.Content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Nerosoft.Euonia.Bus;
using Nerosoft.Starfish.Domain;

namespace Nerosoft.Starfish.Application;

internal partial class LoggingEventSubscriber
{
private const string MODULE_AUTH = "auth";

/// <summary>
/// 处理用户认证成功事件
/// </summary>
/// <param name="event"></param>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <exception cref="NotImplementedException"></exception>
[Subscribe]
public Task HandleAsync(UserAuthSucceedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
var command = new OperateLogCreateCommand
{
Module = MODULE_AUTH,
Type = @event.AuthType,
UserName = @event.UserName,
OperateTime = DateTime.Now,
Description = Resources.IDS_MESSAGE_LOGS_AUTH_SUCCEED,
RequestTraceId = context.RequestTraceId
};
return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
}

/// <summary>
/// 处理用户认证失败事件
/// </summary>
/// <param name="event"></param>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <exception cref="NotImplementedException"></exception>
[Subscribe]
public Task HandleAsync(UserAuthFailedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
var command = new OperateLogCreateCommand
{
Module = MODULE_AUTH,
Type = @event.AuthType,
Description = Resources.IDS_MESSAGE_LOGS_AUTH_FAILED,
OperateTime = DateTime.Now,
RequestTraceId = context.RequestTraceId,
Error = @event.Error
};

return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
}
}
Loading

0 comments on commit 411e0b4

Please sign in to comment.