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

36 lines
893 B
C#

using AGSS.Models;
using AGSS.Models.Entities;
using Microsoft.AspNetCore.Identity;
public class UserService
{
private readonly UserManager<UserModel> _userManager;
public UserService(UserManager<UserModel> userManager)
{
_userManager = userManager;
}
public async Task<UserProfile> GetUserProfileAsync(string userId)
{
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
throw new ArgumentException("User not found");
}
return new UserProfile
{
Id = user.Id,
UserName = user.UserName,
Email = user.Email,
Sex = user.Sex,
Description = user.Description,
Config = user.Config,
JobCode = user.JobCode,
JobName = user.JobName,
Birthday = user.Birthday
};
}
}