2025-07-08 23:06:19 +08:00
|
|
|
|
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]
|
2025-07-09 15:40:47 +08:00
|
|
|
|
[Route("api/v1/[controller]/[action]")]
|
2025-07-08 23:06:19 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|