U:调整所有代码格式

This commit is contained in:
jimmy committed 2025-12-30 09:17:25 +08:00
1 parent d133bacf55
commit 155b67e831
342 files changed
+9431 -9868

No files matched your search

@@ -48,7 +48,7 @@ public class AuthController : BaseController
var token = GenerateSimpleToken(username);
// 设置 Cookie
SetCookie(context, "auth_token", token, expiresInSeconds: 3600);
SetCookie(context, "auth_token", token, 3600);
await WriteSuccessResponseAsync(context, new
{
@@ -156,7 +156,7 @@ public class AuthController : BaseController
}
var newToken = GenerateSimpleToken(username);
SetCookie(context, "auth_token", newToken, expiresInSeconds: 3600);
SetCookie(context, "auth_token", newToken, 3600);
await WriteSuccessResponseAsync(context, new
{
@@ -199,8 +199,8 @@ public class SimpleAuthenticationProvider : IAuthenticationProvider
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, username),
new Claim(ClaimTypes.Role, role)
new(ClaimTypes.Name, username),
new(ClaimTypes.Role, role)
};
var identity = new ClaimsIdentity(claims, "SimpleAuth");
@@ -216,4 +216,4 @@ public class SimpleAuthenticationProvider : IAuthenticationProvider
return Task.FromResult<ClaimsPrincipal?>(null);
}
}
}
@@ -16,7 +16,7 @@ public class ProductController : BaseController
new Product { Id = 1, Name = "笔记本电脑", Price = 5999.00m, Stock = 50, Category = "电子产品" },
new Product { Id = 2, Name = "无线鼠标", Price = 99.00m, Stock = 200, Category = "电子产品" },
new Product { Id = 3, Name = "机械键盘", Price = 399.00m, Stock = 100, Category = "电子产品" },
new Product { Id = 4, Name = "显示器", Price = 1299.00m, Stock = 30, Category = "电子产品" },
new Product { Id = 4, Name = "显示器", Price = 1299.00m, Stock = 30, Category = "电子产品" }
};
/// <summary>
@@ -109,14 +109,12 @@ public class ProductController : BaseController
var stockUpdate = await ReadJsonBodyAsync<Dictionary<string, object>>(context);
if (stockUpdate != null && stockUpdate.TryGetValue("quantity", out var quantityObj))
{
if (int.TryParse(quantityObj.ToString(), out var quantity))
{
product.Stock = quantity;
await WriteSuccessResponseAsync(context, product, "库存更新成功");
return;
}
}
await BadRequestAsync(context, "无效的库存数量");
}
@@ -190,4 +188,4 @@ public class Product
public decimal Price { get; set; }
public int Stock { get; set; }
public string Category { get; set; } = string.Empty;
}
}
@@ -168,4 +168,4 @@ public class User
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Role { get; set; } = "User";
}
}
@@ -47,7 +47,8 @@ public class ExampleProgram
// 配置服务 - 注册认证提供者
builder.ConfigureServices(services =>
{
services.AddSingleton<Sharp.NetServer.Abstractions.IAuthenticationProvider, SimpleAuthenticationProvider>();
services
.AddSingleton<Sharp.NetServer.Abstractions.IAuthenticationProvider, SimpleAuthenticationProvider>();
});
// 启用限流 - 防止滥用
@@ -225,4 +226,4 @@ public class ExampleProgram
Console.WriteLine(" - Token 有效期: 1小时");
Console.WriteLine(" - 某些接口有限流保护");
}
}
}