68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MilliSim.Common.Dtos;
|
|
using MilliSim.Common.Models;
|
|
using MilliSim.Services;
|
|
|
|
namespace MilliSim.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/auth")]
|
|
public class AuthController : ControllerBase
|
|
{
|
|
private readonly IAuthService _authService;
|
|
|
|
public AuthController(IAuthService authService)
|
|
{
|
|
_authService = authService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取验证码
|
|
/// </summary>
|
|
[HttpGet("captcha")]
|
|
public async Task<ApiResponse<CaptchaResult>> GetCaptcha()
|
|
{
|
|
return await _authService.GetCaptchaAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 登录
|
|
/// </summary>
|
|
[HttpPost("login")]
|
|
public async Task<ApiResponse<LoginResponse>> Login([FromBody] LoginRequest request)
|
|
{
|
|
return await _authService.LoginAsync(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改密码
|
|
/// </summary>
|
|
[Authorize]
|
|
[HttpPost("change-password")]
|
|
public async Task<ApiResponse> ChangePassword([FromBody] ChangePasswordRequest request)
|
|
{
|
|
return await _authService.ChangePasswordAsync(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取个人信息
|
|
/// </summary>
|
|
[Authorize]
|
|
[HttpGet("profile")]
|
|
public async Task<ApiResponse<UserDto>> GetProfile()
|
|
{
|
|
return await _authService.GetProfileAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新个人信息
|
|
/// </summary>
|
|
[Authorize]
|
|
[HttpPost("profile")]
|
|
public async Task<ApiResponse<UserDto>> UpdateProfile([FromBody] UpdateProfileRequest request)
|
|
{
|
|
return await _authService.UpdateProfileAsync(request);
|
|
}
|
|
}
|