105040 Add 用户管理模块
This commit is contained in:
parent
04f8d9e15d
commit
713e57c424
|
|
@ -0,0 +1,30 @@
|
||||||
|
using LFlow.Base.Interfaces;
|
||||||
|
using LFlow.Base.Utils;
|
||||||
|
using LFlow.UserManagement.Model;
|
||||||
|
using LFlow.UserManagement.Service;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement.Controller
|
||||||
|
{
|
||||||
|
public class UserManagementController(IUserManagementService service) : BaseController
|
||||||
|
{
|
||||||
|
[HttpPost]
|
||||||
|
public ApiResult<UserDto>? Login(UserDto user)
|
||||||
|
{
|
||||||
|
return Success(service.Login(user));
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public ApiResult<UserDto> Register(UserDto user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Success(service.Register(user));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Fail<UserDto>(null, ex.Message, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<OutputPath>../LFlow_Bin/Services/</OutputPath>
|
||||||
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
|
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||||
|
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LFlow.Base\LFlow.Base.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
using LFlow.Base.Interfaces;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement.Model
|
||||||
|
{
|
||||||
|
public class UserDto : IModel
|
||||||
|
{
|
||||||
|
public string? ID
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? UserName
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
public string? UserEmail
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
public string? UserPassword
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
using LFlow.Base.Interfaces;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement.Model
|
||||||
|
{
|
||||||
|
[SugarTable("T_U_USERINFO")]
|
||||||
|
public class UserModel : IDataModel
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public string ID
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UserName
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
public string UserEmail
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
public string UserPassword
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using LFlow.Base.Default;
|
||||||
|
using LFlow.UserManagement.Model;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement.Repository
|
||||||
|
{
|
||||||
|
internal class UserManagementRepo(ISqlSugarClient client) : DefaultCurdRepo<UserModel, string>(client)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using LFlow.Base.Interfaces;
|
||||||
|
using LFlow.UserManagement.Model;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement.Service
|
||||||
|
{
|
||||||
|
public interface IUserManagementService : IService//<VersionDto>
|
||||||
|
{
|
||||||
|
UserDto? Login(UserDto user);
|
||||||
|
Task<UserDto>? LoginAsync(UserDto user);
|
||||||
|
|
||||||
|
UserDto? Register(UserDto user);
|
||||||
|
Task<UserDto>? RegisterAsync(UserDto user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
using LFlow.Base.Interfaces;
|
||||||
|
using LFlow.Base.Utils;
|
||||||
|
using LFlow.UserManagement.Model;
|
||||||
|
using LFlow.UserManagement.Util;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement.Service
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 在线管理服务
|
||||||
|
/// </summary>
|
||||||
|
public class UserManagementService(IRepo<UserModel, string> repo) : IUserManagementService
|
||||||
|
{
|
||||||
|
public UserDto? Login(UserDto user)
|
||||||
|
{
|
||||||
|
var userPwd = PasswordHelper.HashPassword(user.UserPassword);
|
||||||
|
|
||||||
|
var userModel = repo.WhereSearchId(new UserModel
|
||||||
|
{
|
||||||
|
UserName = user.UserName,
|
||||||
|
UserPassword = userPwd
|
||||||
|
});
|
||||||
|
|
||||||
|
if (userModel == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var loginedUser = repo.Get(userModel.FirstOrDefault());
|
||||||
|
loginedUser.UserPassword = "";
|
||||||
|
return loginedUser.MapTo<UserDto>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<UserDto>? LoginAsync(UserDto user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(this.Login(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserDto? Register(UserDto user)
|
||||||
|
{
|
||||||
|
if (user.UserEmail == null || user.UserName == null || user.UserPassword == null)
|
||||||
|
{
|
||||||
|
throw new Exception("用户名、密码、邮箱不能为空");
|
||||||
|
}
|
||||||
|
var userPwd = PasswordHelper.HashPassword(user.UserPassword);
|
||||||
|
var ids = repo.WhereSearchId(new UserModel
|
||||||
|
{
|
||||||
|
UserName = user.UserName
|
||||||
|
});
|
||||||
|
if (ids != null && ids.Count > 0)
|
||||||
|
{
|
||||||
|
throw new Exception("用户名已存在");
|
||||||
|
}
|
||||||
|
var userModel = new UserModel
|
||||||
|
{
|
||||||
|
ID = Guid.NewGuid().ToString(),
|
||||||
|
UserName = user.UserName,
|
||||||
|
UserEmail = user.UserEmail,
|
||||||
|
UserPassword = userPwd
|
||||||
|
};
|
||||||
|
var savedUser = repo.SaveOrUpdate(userModel, false).MapTo<UserDto>();
|
||||||
|
savedUser.UserPassword = "";
|
||||||
|
return savedUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<UserDto> RegisterAsync(UserDto user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(this.Register(user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
using LFlow.Base.Interfaces;
|
||||||
|
using LFlow.Base.Utils;
|
||||||
|
using LFlow.UserManagement.Model;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Serilog;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement
|
||||||
|
{
|
||||||
|
public class UserManegementModule : IModule
|
||||||
|
{
|
||||||
|
public void ConfigureModule(IServiceCollection services)
|
||||||
|
{
|
||||||
|
CodeFirst.AddType(typeof(UserModel));
|
||||||
|
var assembly = Assembly.GetAssembly(typeof(UserManegementModule))!;
|
||||||
|
var types = assembly.GetTypes().ToList();
|
||||||
|
RegisterModule.RegisterAllService(types, services);
|
||||||
|
RegisterModule.RegisterAllRepo(types, services);
|
||||||
|
RegisterModule.RegisterAllModel(types, services);
|
||||||
|
services.AddControllers().AddApplicationPart(assembly);
|
||||||
|
Log.Logger?.Information("UserManegementModule ConfigureModule done");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace LFlow.UserManagement.Util
|
||||||
|
{
|
||||||
|
public class PasswordHelper
|
||||||
|
{
|
||||||
|
public static string HashPassword(string password)
|
||||||
|
{
|
||||||
|
byte[] data = Encoding.Default.GetBytes(password);
|
||||||
|
byte[] hashData = MD5.HashData(data);
|
||||||
|
StringBuilder sb = new();
|
||||||
|
foreach (byte b in hashData)
|
||||||
|
{
|
||||||
|
sb.Append(b.ToString("x2"));
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace LFlow.User;
|
namespace LFlow.VersionManagement;
|
||||||
|
|
||||||
public class VersionManagementModule : IModule
|
public class VersionManagementModule : IModule
|
||||||
{
|
{
|
||||||
|
|
@ -14,8 +14,8 @@ public class VersionManagementModule : IModule
|
||||||
CodeFirst.AddType(typeof(VersionModel));
|
CodeFirst.AddType(typeof(VersionModel));
|
||||||
var assembly = Assembly.GetAssembly(typeof(VersionManagementModule))!;
|
var assembly = Assembly.GetAssembly(typeof(VersionManagementModule))!;
|
||||||
var types = assembly.GetTypes().ToList();
|
var types = assembly.GetTypes().ToList();
|
||||||
RegisterModule.RegisterAllService(types, services);
|
types.RegisterAllService(services);
|
||||||
RegisterModule.RegisterAllRepo(types, services);
|
types.RegisterAllRepo(services);
|
||||||
//RegisterModule.RegisterAllModel(types, services);
|
//RegisterModule.RegisterAllModel(types, services);
|
||||||
services.AddControllers().AddApplicationPart(assembly);
|
services.AddControllers().AddApplicationPart(assembly);
|
||||||
Log.Logger?.Information("VersionManagementModule ConfigureModule done");
|
Log.Logger?.Information("VersionManagementModule ConfigureModule done");
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LFlow.Base", "LFlow.Base\LF
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LFlow.VersionManagement", "LFlow.VersionManagement\LFlow.VersionManagement.csproj", "{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LFlow.VersionManagement", "LFlow.VersionManagement\LFlow.VersionManagement.csproj", "{D52CC594-B10C-4FC0-8B7A-68CE0645A95D}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.OnlineManegement", "LFlow.OnlineManegement\LFlow.OnlineManegement.csproj", "{E849310F-64AD-453A-A2AA-557731508BF1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LFlow.OnlineManegement", "LFlow.OnlineManegement\LFlow.OnlineManegement.csproj", "{E849310F-64AD-453A-A2AA-557731508BF1}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.UserManagement", "LFlow.UserManagement\LFlow.UserManagement.csproj", "{DA68CE22-AC53-40BD-AB2A-5C52DFDDD548}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
@ -27,6 +29,10 @@ Global
|
||||||
{E849310F-64AD-453A-A2AA-557731508BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{E849310F-64AD-453A-A2AA-557731508BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{E849310F-64AD-453A-A2AA-557731508BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{E849310F-64AD-453A-A2AA-557731508BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{E849310F-64AD-453A-A2AA-557731508BF1}.Release|Any CPU.Build.0 = Release|Any CPU
|
{E849310F-64AD-453A-A2AA-557731508BF1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DA68CE22-AC53-40BD-AB2A-5C52DFDDD548}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DA68CE22-AC53-40BD-AB2A-5C52DFDDD548}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DA68CE22-AC53-40BD-AB2A-5C52DFDDD548}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DA68CE22-AC53-40BD-AB2A-5C52DFDDD548}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue