mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-06-05 15:39:45 +08:00
feat(auth): add configuration options for user registration and anonymous image hosting
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -9,12 +9,13 @@ using Foxel.Services.Storage;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Text.Json; // Added for JsonSerializer in GetTelegramFile if it were kept
|
||||
using Foxel.Services.Configuration; // Added for IConfigService
|
||||
|
||||
namespace Foxel.Api;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/picture")]
|
||||
public class PictureController(IPictureService pictureService, IStorageService storageService, ILogger<PictureController> logger) : BaseApiController
|
||||
public class PictureController(IPictureService pictureService, IStorageService storageService, ILogger<PictureController> logger, IConfigService configuration) : BaseApiController
|
||||
{
|
||||
private readonly ILogger<PictureController> _logger = logger;
|
||||
|
||||
@@ -74,6 +75,16 @@ public class PictureController(IPictureService pictureService, IStorageService s
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
|
||||
if (userId == null)
|
||||
{
|
||||
var enableAnonymousUpload = configuration["AppSettings:EnableAnonymousImageHosting"];
|
||||
if (string.Equals(enableAnonymousUpload, "false", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Error<PictureResponse>("匿名上传功能已关闭,请登录后操作", 403);
|
||||
}
|
||||
}
|
||||
|
||||
await using var stream = request.File.OpenReadStream();
|
||||
var result = await pictureService.UploadPictureAsync(
|
||||
request.File.FileName,
|
||||
|
||||
Reference in New Issue
Block a user