AGSSbackend/AGSS/Controllers/User/UserControllers.cs

45 lines
1.1 KiB
C#
Raw Normal View History

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]/[action]")]
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);
}
}
}