修改User模块,同步原始代码

This commit is contained in:
chfei committed 2026-10-23 15:42:37 +08:00
1 parent 4a5fada435
commit 78b0c2bb2e
47 files changed
+2939 -193

No files matched your search

+10 -13
View File
@@ -1,26 +1,27 @@
using Asp.Versioning;
using Asp.Versioning;
using MAX.Framework.Dtos;
using MAX.Framework.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using Store.Users.Contracts;
namespace Store.Api.Controllers
{
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[Route("/v{version:apiVersion}/[controller]/[action]")]
public class AuthController : ControllerBase
{
//private readonly IUserService _userService;
private readonly IUserAuthenticationService _users;
private readonly ITokenService _tokenService;
private readonly ICurrentUser _currentUser;
private readonly IOnlineUserStore _onlineUserStore;
private readonly ILogger<AuthController> _logger;
public AuthController(ITokenService tokenService, ICurrentUser currentUser, IOnlineUserStore onlineUserStore, ILogger<AuthController> logger)
public AuthController(ITokenService tokenService, ICurrentUser currentUser, IOnlineUserStore onlineUserStore, ILogger<AuthController> logger, IUserAuthenticationService users)
{
//_userService = userService;
_users = users;
_tokenService = tokenService;
_currentUser = currentUser;
_onlineUserStore = onlineUserStore;
@@ -34,22 +35,19 @@ namespace Store.Api.Controllers
[AllowAnonymous]
public async Task<ApiResultBase> Login([FromBody] LoginRequest request)
{
_logger.LogError("login errr");
_logger.LogInformation("login");
if (request is null || string.IsNullOrWhiteSpace(request.UserName) || string.IsNullOrWhiteSpace(request.Password))
{
return ApiResult.Fail("用户名或密码不能为空", 400);
}
//UserDto? user = await _userService.LoginAsync(request.UserName, request.Password);
//if (user is null)
//{
// return ApiResult.Error("用户名或密码错误", 401);
//}
// 认证通过后才签发令牌,权限信息以用户模块中的数据库记录为准。
var user = await _users.Authenticate(request.UserName, request.Password, HttpContext.RequestAborted);
if (user is null) return ApiResult.Fail("用户名或密码错误", 401);
var claims = new List<Claim>
{
new(JwtClaimTypes.UserName, request.UserName),
new(JwtClaimTypes.UserName, user.UserName),
};
TokenResult token = _tokenService.CreateToken(claims);
@@ -108,4 +106,3 @@ namespace Store.Api.Controllers
public string Password { get; set; } = string.Empty;
}
}
+10 -4
View File
@@ -1,4 +1,5 @@
using Asp.Versioning;
using MAX.Framework.Conventions;
using MAX.Framework.DependencyInjection;
using Scalar.AspNetCore;
@@ -21,16 +22,21 @@ public partial class Program
// // 兼容迁移的同步控制器:允许同步读写请求/响应 IO(旧 asmx 行为)
// options.AllowSynchronousIO = true;
//});
builder.Services.AddControllers();
builder.Services.AddControllers(options =>
{
options.Conventions.Add(new ApiRoutePrefixConvention());
});
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;// 未指定时使用默认版本
options.ReportApiVersions = true;
options.ApiVersionReader = new UrlSegmentApiVersionReader();
}).AddMvc().AddApiExplorer(options =>
{
options.GroupNameFormat = "'v'V";
// 保留次版本号,避免 1.0 与 1.1 都映射为 v1,造成 OpenAPI 服务重复注册。
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
}).AddOpenApi();
@@ -49,8 +55,8 @@ public partial class Program
app.MapScalarApiReference(options =>
{
options.DefaultHttpClient = new(ScalarTarget.CSharp, ScalarClient.HttpClient);
options.Title = "商铺管理API V1";
options.AddDocuments(new[] { "v1", "v2" });
options.Title = "商铺管理API";
options.AddDocuments(app.DescribeApiVersions().Select(version => version.GroupName).ToArray());
});
}
+2 -2
View File
@@ -5,7 +5,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "scalar/v1",
"launchUrl": "scalar/",
"applicationUrl": "http://localhost:14312",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
@@ -15,7 +15,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "scalar/v1",
"launchUrl": "scalar/",
"applicationUrl": "https://localhost:7241;http://localhost:14312",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
-25
View File
@@ -7,31 +7,6 @@
},
"ConnectionStrings": {
"DefaultConnection": "Server=192.168.0.200;Port=3306;Database=mysql;Uid=root;Pwd=123456;",
"KJDConnection": "Server=192.168.0.200;Port=3306;Database=mysql;Uid=root;Pwd=123456;",
"ConnKJD": "Server=192.168.0.200;Port=3306;Database=mysql;Uid=root;Pwd=123456;"
//"KJDConnection": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-hl51pkfr.sql.tencentcdb.com';Port=27660;User Id='kjd';Password='Temukjd0625';Charset=utf8mb4;",
//"KJDBAKConnection": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-9s7x16mt.sql.tencentcdb.com';Port=24049;User Id='kjdbak';Password='Temukjd0126';Charset=utf8mb4;",
//"ConnKJD": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-hl51pkfr.sql.tencentcdb.com';Port=27660;User Id='kjd';Password='Temukjd0625';Charset=utf8mb4;",
//"ConnKJDBAK": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-9s7x16mt.sql.tencentcdb.com';Port=24049;User Id='kjdbak';Password='Temukjd0126';Charset=utf8mb4;"
},
"KJDConfig": {
"UpdateVersion": "525",
"UpdateFileDir": "C:\\inetpub\\wwwroot\\kjd_update",
"UpdateNewUrl": "http://weidian.e57.cn/kjd_update/",
"UpdateExe": "http://1.13.195.131:9000/Download/Update.exe",
"UpdateExeChk": "CE4A009B7AA330314F03EEA0C3AB23F9",
"LowVersion": "523",
"LimitVersion": "823",
"GetReturnPackage": "true",
"GetWXRecommendHotProd": "true",
"GetWXRecommendHotProdOncePerDay": "false",
"GetWXRecommendHotProdMinViewUv": "200",
"GetWXRecommendHotProdInterval": "3",
"IsKeepBase64UploadImgFile": "0",
"UpdateWxFindOrderFileDir": "C:\\inetpub\\wwwroot\\find_order_update",
"UpdateWxFindOrderUrl": "http://weidian.e57.cn/find_order_update/",
"WxFindOrderLimitVersion": "172",
"WxFindOrderLowVersion": "99"
},
"Jwt": {
"Issuer": "StoreHub",