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)
|
||||
|
Reference in New Issue
Block a user