修复
This commit is contained in:
@@ -47,6 +47,39 @@ namespace FutureMailAPI.Controllers
|
||||
result);
|
||||
}
|
||||
|
||||
// 兼容前端请求格式的创建邮件接口
|
||||
[HttpPost("create")]
|
||||
public async Task<IActionResult> CreateMailCompat([FromBody] SentMailCreateCompatDto createDto)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ApiResponse<SentMailResponseDto>.ErrorResult("输入数据无效"));
|
||||
}
|
||||
|
||||
// 从JWT令牌中获取当前用户ID
|
||||
var currentUserId = GetCurrentUserId();
|
||||
|
||||
if (currentUserId <= 0)
|
||||
{
|
||||
return Unauthorized(ApiResponse<SentMailResponseDto>.ErrorResult("未授权访问"));
|
||||
}
|
||||
|
||||
// 转换为内部DTO
|
||||
var internalDto = createDto.ToInternalDto();
|
||||
|
||||
var result = await _mailService.CreateMailAsync(currentUserId, internalDto);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
return BadRequest(result);
|
||||
}
|
||||
|
||||
return CreatedAtAction(
|
||||
nameof(GetMail),
|
||||
new { mailId = result.Data!.Id },
|
||||
result);
|
||||
}
|
||||
|
||||
[HttpGet("{mailId}")]
|
||||
public async Task<IActionResult> GetMail(int mailId)
|
||||
{
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using FutureMailAPI.Data;
|
||||
using FutureMailAPI.Models;
|
||||
using FutureMailAPI.Helpers;
|
||||
|
||||
namespace FutureMailAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/temp-fix")]
|
||||
public class TempFixController : ControllerBase
|
||||
{
|
||||
private readonly FutureMailDbContext _context;
|
||||
private readonly IPasswordHelper _passwordHelper;
|
||||
|
||||
public TempFixController(FutureMailDbContext context, IPasswordHelper passwordHelper)
|
||||
{
|
||||
_context = context;
|
||||
_passwordHelper = passwordHelper;
|
||||
}
|
||||
|
||||
[HttpPost("fix-passwords")]
|
||||
public async Task<IActionResult> FixPasswordHashes()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取所有用户
|
||||
var users = await _context.Users.ToListAsync();
|
||||
int fixedCount = 0;
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
// 如果salt为空但passwordHash有值,说明需要修复
|
||||
if (string.IsNullOrEmpty(user.Salt) && !string.IsNullOrEmpty(user.PasswordHash))
|
||||
{
|
||||
// 使用默认密码重新设置密码哈希
|
||||
var newPasswordHash = _passwordHelper.HashPassword("password123");
|
||||
user.PasswordHash = newPasswordHash;
|
||||
user.Salt = _passwordHelper.GenerateSalt();
|
||||
fixedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Ok(new {
|
||||
success = true,
|
||||
message = $"已修复 {fixedCount} 个用户的密码哈希",
|
||||
fixedUsers = fixedCount
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(new {
|
||||
success = false,
|
||||
message = $"修复失败: {ex.Message}"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("users")]
|
||||
public async Task<IActionResult> GetUsers()
|
||||
{
|
||||
var users = await _context.Users
|
||||
.Select(u => new {
|
||||
u.Id,
|
||||
u.Username,
|
||||
u.Email,
|
||||
PasswordHashLength = u.PasswordHash.Length,
|
||||
HasSalt = !string.IsNullOrEmpty(u.Salt)
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(users);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user