This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user