AGSSbackend/AGSS/Controllers/User/UserControllers.cs
luolan ca93d49780 重构用户控制器并引入身份验证服务
- 移除 `UserInfoController`,新增 `UserControllers` 使用 `UserService`
- 添加 `UserService` 用于处理用户信息
- 新增 `UserProfile` DTO
- 添加数据库迁移以支持用户表结构
2025-07-08 23:06:19 +08:00

45 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Security.Claims;
using AGSS.Models.Entities;
using AGSS.Models.Template;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
namespace AGSS.Controllers.User;
[Authorize]
[Route("api/v1/[controller]")]
public class UserControllers:ControllerBase
{
private readonly UserService _userService;
public UserControllers(UserService userService, UserManager<UserModel> userManager)
{
_userService = userService;
}
[HttpGet]
public async Task<IActionResult> My()
{
string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
if (string.IsNullOrEmpty(userId))
{
return Ok(new ReturnTemplate(500,"获取用户失败JWT解析错误",null));
}
try
{
var userProfile = await _userService.GetUserProfileAsync(userId);
return Ok(new ReturnTemplate(200,"获取成功!",userProfile));
}
catch (ArgumentException ex)
{
return NotFound(ex.Message);
}
}
}