This commit is contained in:
2026-02-08 18:43:20 +08:00
parent ed95bdddac
commit eff83a9f68
11 changed files with 132 additions and 39 deletions
@@ -8,6 +8,7 @@ using IM_API.VOs.Auth;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
namespace IM_API.Controllers
{
@@ -39,13 +40,20 @@ namespace IM_API.Controllers
[HttpPost]
public async Task<IActionResult> Login(LoginRequestDto dto)
{
Stopwatch sw = Stopwatch.StartNew();
var user = await _authService.LoginAsync(dto);
_logger.LogInformation("服务耗时: {ms}ms", sw.ElapsedMilliseconds);
var userInfo = _mapper.Map<UserInfoDto>(user);
_logger.LogInformation("序列化耗时: {ms}ms", sw.ElapsedMilliseconds);
//生成凭证
(string token,DateTime expiresAt) = _jwtService.CreateAccessTokenForUser(user.Id,user.Username,"user");
_logger.LogInformation("Token生成耗时: {ms}ms", sw.ElapsedMilliseconds);
//生成刷新凭证
string refreshToken = await _refreshTokenService.CreateRefreshTokenAsync(user.Id);
_logger.LogInformation("RefreshToken生成耗时: {ms}ms", sw.ElapsedMilliseconds);
var res = new BaseResponse<LoginVo>(new LoginVo(userInfo,token,refreshToken, expiresAt));
_logger.LogInformation("总耗时: {ms}ms", sw.ElapsedMilliseconds);
return Ok(res);
}
[HttpPost]