feat(auth): add configuration options for user registration and anonymous image hosting

This commit is contained in:
shiyu
2025-06-10 16:42:39 +08:00
parent b5931de344
commit 853efaa2fe
6 changed files with 167 additions and 92 deletions

View File

@@ -9,7 +9,7 @@ using Foxel.Services.Configuration;
namespace Foxel.Controllers;
[Route("api/auth")]
public class AuthController(IAuthService authService) : BaseApiController
public class AuthController(IAuthService authService, IConfigService configuration) : BaseApiController
{
[HttpPost("register")]
public async Task<ActionResult<BaseResult<AuthResponse>>> Register([FromBody] RegisterRequest request)
@@ -19,6 +19,13 @@ public class AuthController(IAuthService authService) : BaseApiController
return Error<AuthResponse>("请求数据无效");
}
// 检查是否允许新用户注册
var enableRegistration = configuration["AppSettings:EnableRegistration"];
if (string.Equals(enableRegistration, "false", StringComparison.OrdinalIgnoreCase))
{
return Error<AuthResponse>("新用户注册功能已关闭");
}
var (success, message, user) = await authService.RegisterUserAsync(request);
if (!success)
{