更新用户控制器中的JWT声明名称,并在用户资料中添加菜单信息字段

This commit is contained in:
罗澜大帅哥 2025-07-10 23:09:03 +08:00
parent 9f407c422c
commit 062c5f9477
3 changed files with 11 additions and 8 deletions

View File

@ -39,11 +39,11 @@ public class UserControllers:ControllerBase
[HttpGet] [HttpGet]
public async Task<IActionResult> My() public async Task<IActionResult> My()
{ {
string userId = this.User.FindFirst(JwtRegisteredClaimNames.Sub)!.Value;
if (string.IsNullOrEmpty(userId))
{
return Ok(new ReturnTemplate(500,"获取用户失败JWT解析错误",null));
} string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
try try
{ {
@ -54,6 +54,5 @@ public class UserControllers:ControllerBase
{ {
return NotFound(ex.Message); return NotFound(ex.Message);
} }
} }
} }

View File

@ -11,4 +11,6 @@ public class UserProfile
public string? JobCode { get; set; } public string? JobCode { get; set; }
public string? JobName { get; set; } public string? JobName { get; set; }
public string? Birthday { get; set; } public string? Birthday { get; set; }
public string? MenuCode { get; set; }
public string? MenuName { get; set; }
} }

View File

@ -29,7 +29,9 @@ public class UserService
Config = user.Config, Config = user.Config,
JobCode = user.JobCode, JobCode = user.JobCode,
JobName = user.JobName, JobName = user.JobName,
Birthday = user.Birthday Birthday = user.Birthday,
MenuCode = user.MenuCode,
MenuName = user.MenuName
}; };
} }
} }