This commit is contained in:
		@@ -4,4 +4,11 @@
 | 
			
		||||
@code {
 | 
			
		||||
	[Parameter]
 | 
			
		||||
	public StudentDto StudentDto{ get; set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,16 @@ namespace TechHelper.Client.Services
 | 
			
		||||
 | 
			
		||||
		public Task<ResponseDto> CreateClass(UserRegistrationToClassDto userClass)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				return Task.FromResult(new ResponseDto { IsSuccessfulRegistration = true });	
 | 
			
		||||
			}
 | 
			
		||||
			catch (Exception ex)
 | 
			
		||||
			{
 | 
			
		||||
				// 实际应用中,这里应该加入日志记录
 | 
			
		||||
				Console.WriteLine($"Error in CreateClass: {ex.Message}");
 | 
			
		||||
				return Task.FromResult(new ResponseDto { IsSuccessfulRegistration = false, Errors = new string[] { ex.Message } });
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public async Task<ApiResponse> GetClassStudents()
 | 
			
		||||
@@ -56,7 +65,25 @@ namespace TechHelper.Client.Services
 | 
			
		||||
 | 
			
		||||
		public StudentDto GetStudents(byte Class)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				var result = _client.PostAsJsonAsync("class/getClassStudents", Class);
 | 
			
		||||
				var content = result.Result.Content.ReadAsStringAsync();
 | 
			
		||||
				if (content.Result != null)
 | 
			
		||||
				{
 | 
			
		||||
					var users = JsonConvert.DeserializeObject<StudentDto>(content.Result);
 | 
			
		||||
					return users;
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
					return new StudentDto();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			catch (Exception ex)
 | 
			
		||||
			{
 | 
			
		||||
				Console.WriteLine($"获取失败,{ex.Message}, InnerException: {ex.InnerException}");
 | 
			
		||||
				return new StudentDto();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public async Task<ResponseDto> UserRegister(UserRegistrationToClassDto userRegistrationToClassDto)
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,10 @@ using Entities.Contracts;
 | 
			
		||||
 | 
			
		||||
namespace TechHelper.Controllers
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// 账户管理控制器
 | 
			
		||||
	/// 处理用户注册、登录、密码重置等认证相关操作
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	[Route("api/account")]
 | 
			
		||||
	[ApiController]
 | 
			
		||||
	public class AccountController : ControllerBase
 | 
			
		||||
@@ -19,6 +23,13 @@ namespace TechHelper.Controllers
 | 
			
		||||
		private IAuthenticationService _authenticationService;
 | 
			
		||||
		private readonly IEmailSender _emailSender;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 初始化账户控制器
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="userManager">用户管理服务</param>
 | 
			
		||||
		/// <param name="userRegistrationService">用户注册服务</param>
 | 
			
		||||
		/// <param name="emailSender">邮件发送服务</param>
 | 
			
		||||
		/// <param name="authenticationService">认证服务</param>
 | 
			
		||||
		public AccountController(UserManager<User> userManager,
 | 
			
		||||
			IUserRegistrationService userRegistrationService,
 | 
			
		||||
			IEmailSender emailSender,
 | 
			
		||||
@@ -30,6 +41,13 @@ namespace TechHelper.Controllers
 | 
			
		||||
			_authenticationService = authenticationService;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 注册新用户
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="userForRegistrationDto">用户注册信息数据传输对象</param>
 | 
			
		||||
		/// <returns>注册结果响应</returns>
 | 
			
		||||
		/// <response code="201">用户注册成功</response>
 | 
			
		||||
		/// <response code="400">注册请求无效或验证失败</response>
 | 
			
		||||
		[HttpPost("register")]
 | 
			
		||||
		public async Task<IActionResult> RegisterUsesr(
 | 
			
		||||
			[FromBody] UserForRegistrationDto userForRegistrationDto)
 | 
			
		||||
@@ -93,6 +111,14 @@ namespace TechHelper.Controllers
 | 
			
		||||
			#endregion
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 用户登录认证
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="userForAuthentication">用户认证信息数据传输对象</param>
 | 
			
		||||
		/// <returns>认证结果响应</returns>
 | 
			
		||||
		/// <response code="200">登录成功,返回认证令牌</response>
 | 
			
		||||
		/// <response code="401">认证失败,用户名或密码错误</response>
 | 
			
		||||
		/// <response code="400">请求无效或验证失败</response>
 | 
			
		||||
		[HttpPost("login")]
 | 
			
		||||
		public async Task<IActionResult> Logion(
 | 
			
		||||
			[FromBody] UserForAuthenticationDto userForAuthentication)
 | 
			
		||||
@@ -158,6 +184,11 @@ namespace TechHelper.Controllers
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 生成两步验证的OTP令牌
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="user">用户对象</param>
 | 
			
		||||
		/// <returns>两步验证响应</returns>
 | 
			
		||||
		private async Task<IActionResult> GenerateOTPFor2StepVerification(User user)
 | 
			
		||||
		{
 | 
			
		||||
			var providers = await _userManager.GetValidTwoFactorProvidersAsync(user);
 | 
			
		||||
@@ -180,6 +211,14 @@ namespace TechHelper.Controllers
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 忘记密码请求
 | 
			
		||||
		/// 发送密码重置令牌到用户邮箱
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="forgotPasswordDto">忘记密码请求数据传输对象</param>
 | 
			
		||||
		/// <returns>操作结果</returns>
 | 
			
		||||
		/// <response code="200">密码重置邮件发送成功</response>
 | 
			
		||||
		/// <response code="400">请求无效或用户不存在</response>
 | 
			
		||||
		[HttpPost("forgotPassword")]
 | 
			
		||||
		public async Task<IActionResult> ForgotPassword(
 | 
			
		||||
			[FromBody] ForgotPasswordDto forgotPasswordDto)
 | 
			
		||||
@@ -203,6 +242,13 @@ namespace TechHelper.Controllers
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 重置用户密码
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="resetPasswordDto">密码重置数据传输对象</param>
 | 
			
		||||
		/// <returns>重置结果响应</returns>
 | 
			
		||||
		/// <response code="200">密码重置成功</response>
 | 
			
		||||
		/// <response code="400">密码重置失败</response>
 | 
			
		||||
		[HttpPost("resetPassword")]
 | 
			
		||||
		public async Task<IActionResult> ResetPassword(
 | 
			
		||||
			[FromBody] ResetPasswordDto resetPasswordDto)
 | 
			
		||||
@@ -231,6 +277,15 @@ namespace TechHelper.Controllers
 | 
			
		||||
			return Ok(new ResetPasswordResponseDto { IsResetPasswordSuccessful = true});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 邮箱确认验证
 | 
			
		||||
		/// 验证用户邮箱确认令牌
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="email">用户邮箱地址</param>
 | 
			
		||||
		/// <param name="token">邮箱确认令牌</param>
 | 
			
		||||
		/// <returns>验证结果</returns>
 | 
			
		||||
		/// <response code="200">邮箱确认成功</response>
 | 
			
		||||
		/// <response code="400">邮箱确认失败</response>
 | 
			
		||||
		[HttpGet("emailconfirmation")]
 | 
			
		||||
		public async Task<IActionResult> EmailConfirmaation([FromQuery] string email,
 | 
			
		||||
			[FromQuery] string token)
 | 
			
		||||
@@ -245,6 +300,14 @@ namespace TechHelper.Controllers
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 两步验证确认
 | 
			
		||||
		/// 验证用户提供的两步验证令牌
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="twoFactorVerificationDto">两步验证数据传输对象</param>
 | 
			
		||||
		/// <returns>验证结果响应</returns>
 | 
			
		||||
		/// <response code="200">验证成功,返回认证令牌</response>
 | 
			
		||||
		/// <response code="400">验证失败</response>
 | 
			
		||||
		[HttpPost("TwoStepVerification")]
 | 
			
		||||
		public async Task<IActionResult> TwoStepVerification(
 | 
			
		||||
			[FromBody] TwoFactorVerificationDto twoFactorVerificationDto)
 | 
			
		||||
 
 | 
			
		||||
@@ -9,18 +9,35 @@ using TechHelper.Services;
 | 
			
		||||
 | 
			
		||||
namespace TechHelper.Server.Controllers
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// 班级管理控制器
 | 
			
		||||
	/// 处理班级相关的操作,如用户注册到班级、获取班级学生等
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	[Route("api/class")]
 | 
			
		||||
	[ApiController]
 | 
			
		||||
	public class ClassController : ControllerBase
 | 
			
		||||
	{
 | 
			
		||||
		private IClassService _classService;
 | 
			
		||||
		private UserManager<User> _userManager;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 初始化班级控制器
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="classService">班级服务</param>
 | 
			
		||||
		/// <param name="userManager">用户管理服务</param>
 | 
			
		||||
		public ClassController(IClassService classService, UserManager<User> userManager)
 | 
			
		||||
		{
 | 
			
		||||
			_classService = classService;
 | 
			
		||||
			_userManager = userManager;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 用户注册到班级
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="toClass">用户注册到班级的数据传输对象</param>
 | 
			
		||||
		/// <returns>操作结果</returns>
 | 
			
		||||
		/// <response code="200">注册成功</response>
 | 
			
		||||
		/// <response code="400">注册失败</response>
 | 
			
		||||
		[HttpPost("userRegiste")]
 | 
			
		||||
		public async Task<IActionResult> UserRegisterToClass(
 | 
			
		||||
			[FromBody] UserRegistrationToClassDto toClass)
 | 
			
		||||
@@ -36,6 +53,13 @@ namespace TechHelper.Server.Controllers
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 获取班级学生列表
 | 
			
		||||
		/// 仅限教师角色访问,根据教师所在班级信息获取学生列表
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <returns>班级学生列表</returns>
 | 
			
		||||
		/// <response code="200">成功获取学生列表</response>
 | 
			
		||||
		/// <response code="400">权限不足或班级信息缺失</response>
 | 
			
		||||
		[HttpPost("getClassStudents")]
 | 
			
		||||
		public async Task<IActionResult> GetClassStudents()
 | 
			
		||||
		{
 | 
			
		||||
@@ -84,6 +108,13 @@ namespace TechHelper.Server.Controllers
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 创建新班级
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="classDto">班级数据传输对象</param>
 | 
			
		||||
		/// <returns>操作结果</returns>
 | 
			
		||||
		/// <response code="200">班级创建成功</response>
 | 
			
		||||
		/// <response code="400">班级创建失败</response>
 | 
			
		||||
		[HttpPost("Create")]
 | 
			
		||||
		public async Task<IActionResult> Create(
 | 
			
		||||
			[FromBody] ClassDto classDto)
 | 
			
		||||
@@ -94,6 +125,13 @@ namespace TechHelper.Server.Controllers
 | 
			
		||||
			return Ok();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 获取指定年级的所有班级列表
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="classDto">年级编号</param>
 | 
			
		||||
		/// <returns>班级列表</returns>
 | 
			
		||||
		/// <response code="200">成功获取班级列表</response>
 | 
			
		||||
		/// <response code="400">获取失败</response>
 | 
			
		||||
		[HttpPost("GetGradeClasses")]
 | 
			
		||||
		public async Task<IActionResult> GetGradeClasses(
 | 
			
		||||
		[FromBody] byte classDto)
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,10 @@ using TechHelper.Server.Services;
 | 
			
		||||
using TechHelper.Server.Repositories;
 | 
			
		||||
using Microsoft.OpenApi.Models;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// TechHelper 服务器应用程序的主入口点
 | 
			
		||||
/// 配置和启动 ASP.NET Core Web API 应用程序
 | 
			
		||||
/// </summary>
 | 
			
		||||
var builder = WebApplication.CreateBuilder(args);
 | 
			
		||||
 | 
			
		||||
builder.Services.AddControllers();                                                              // 添加 MVC 控制器服务 (用于 API)
 | 
			
		||||
 
 | 
			
		||||
@@ -143,6 +143,21 @@ namespace TechHelper.Services
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public Task GetClassStudents(byte Grade, byte Class)
 | 
			
		||||
		{
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				var result = _work.GetRepository<Class>().GetFirstOrDefault(predicate:
 | 
			
		||||
					c => c.Grade == Grade && c.Number == Class,
 | 
			
		||||
					include: i => i
 | 
			
		||||
					.Include(c => c.ClassStudents)
 | 
			
		||||
					.ThenInclude(cs => cs.Student));
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
			catch (Exception ex)
 | 
			
		||||
			{ }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public async Task<ApiResponse> GetGradeClasses(byte Grade)
 | 
			
		||||
		{
 | 
			
		||||
			try
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,6 @@ namespace TechHelper.Services
 | 
			
		||||
		public Task<ApiResponse> GetUserClassRole(Guid user); // List<UserClassRoleDto>
 | 
			
		||||
		public Task<ApiResponse> GetClassStudents(ClassDto classDto); // Class
 | 
			
		||||
		public Task<ApiResponse> GetGradeClasses(byte Grade); // Class
 | 
			
		||||
 | 
			
		||||
		Task GetClassStudents(byte grade, byte id);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,10 @@ using TechHelper.Services;
 | 
			
		||||
 | 
			
		||||
namespace TechHelper.Server.Services
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// 用户服务实现类
 | 
			
		||||
	/// 处理用户相关的业务逻辑操作
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	public class UserServices : IUserSerivces
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
@@ -13,6 +17,12 @@ namespace TechHelper.Server.Services
 | 
			
		||||
		private readonly IClassService _classService;
 | 
			
		||||
		private readonly UserManager<User> _userManager;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 初始化用户服务
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="unitOfWork">工作单元实例</param>
 | 
			
		||||
		/// <param name="classService">班级服务实例</param>
 | 
			
		||||
		/// <param name="userManager">用户管理实例</param>
 | 
			
		||||
		public UserServices(IUnitOfWork unitOfWork, IClassService classService, UserManager<User> userManager)
 | 
			
		||||
		{
 | 
			
		||||
			_unitOfWork = unitOfWork;
 | 
			
		||||
@@ -20,31 +30,62 @@ namespace TechHelper.Server.Services
 | 
			
		||||
			_userManager = userManager;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 添加新用户
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="model">用户实体对象</param>
 | 
			
		||||
		/// <returns>操作结果响应</returns>
 | 
			
		||||
		public Task<ApiResponse> AddAsync(User model)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 删除指定用户
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="id">用户唯一标识符</param>
 | 
			
		||||
		/// <returns>操作结果响应</returns>
 | 
			
		||||
		public Task<ApiResponse> DeleteAsync(Guid id)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 获取所有用户列表
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="query">查询参数对象</param>
 | 
			
		||||
		/// <returns>用户列表响应</returns>
 | 
			
		||||
		public Task<ApiResponse> GetAllAsync(QueryParameter query)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 获取指定用户信息
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="id">用户唯一标识符</param>
 | 
			
		||||
		/// <returns>用户信息响应</returns>
 | 
			
		||||
		public Task<ApiResponse> GetAsync(Guid id)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 获取学生详细信息
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="userId">用户唯一标识符</param>
 | 
			
		||||
		/// <returns>学生详细信息响应</returns>
 | 
			
		||||
		public Task<ApiResponse> GetStudentDetailInfo(Guid userId)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 恢复用户角色信息
 | 
			
		||||
		/// 根据用户所在班级信息恢复用户的角色权限
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="user">用户实体对象</param>
 | 
			
		||||
		/// <returns>操作结果响应</returns>
 | 
			
		||||
		public async Task<ApiResponse> RestoreUserRoleInformation(User user)
 | 
			
		||||
		{
 | 
			
		||||
			var result = await _classService.GetUserClassRole(user.Id);
 | 
			
		||||
@@ -64,11 +105,21 @@ namespace TechHelper.Server.Services
 | 
			
		||||
			return ApiResponse.Error();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 更新用户信息
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="model">用户实体对象</param>
 | 
			
		||||
		/// <returns>操作结果响应</returns>
 | 
			
		||||
		public Task<ApiResponse> UpdateAsync(User model)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// 验证用户信息
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="userId">用户唯一标识符</param>
 | 
			
		||||
		/// <returns>验证结果响应</returns>
 | 
			
		||||
		public Task<ApiResponse> VerifyUserInformation(Guid userId)
 | 
			
		||||
		{
 | 
			
		||||
			throw new NotImplementedException();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user