添加项目文件。
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using IdentityService.Domain;
|
||||
using IdentityService.WebApi.Applications.Auth;
|
||||
using IdentityService.WebApi.Applications.Dtos;
|
||||
using IdentityService.WebApi.Applications.Dtos.Common;
|
||||
using IM.Commons;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace IdentityService.WebApi.Controllers.Auth
|
||||
{
|
||||
[Route("/api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
private readonly AuthService authService;
|
||||
private readonly IIdRepository idRepository;
|
||||
|
||||
public AuthController(AuthService authService, IIdRepository idRepository)
|
||||
{
|
||||
this.authService = authService;
|
||||
this.idRepository = idRepository;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesDefaultResponseType(typeof(Result<LoginResponse>))]
|
||||
public async Task<IActionResult> Login([FromBody] LoginRequest loginRequest)
|
||||
{
|
||||
return Ok(await authService.LoginAsync(loginRequest.UserName, loginRequest.Password));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesDefaultResponseType(typeof(Result<UserResponse>))]
|
||||
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
|
||||
{
|
||||
return Ok(await authService.RegisterAsync(registerRequest.UserName, registerRequest.Password, registerRequest.NickName));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesDefaultResponseType(typeof(Result<LoginResponse>))]
|
||||
public async Task<IActionResult> Refresh([FromBody] RefreshRequest refreshRequest)
|
||||
{
|
||||
return Ok(await authService.RefreshAsync(refreshRequest.RefreshToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace IdentityService.WebApi.Controllers.Auth
|
||||
{
|
||||
public class LoginRequest
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
public class LoginRequestValidator : AbstractValidator<LoginRequest>
|
||||
{
|
||||
public LoginRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.UserName)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
.MaximumLength(20)
|
||||
.MinimumLength(5);
|
||||
|
||||
RuleFor(x => x.Password)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
.MaximumLength(50)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace IdentityService.WebApi.Controllers.Auth
|
||||
{
|
||||
public class RefreshRequest
|
||||
{
|
||||
public string RefreshToken { get; set; }
|
||||
}
|
||||
|
||||
public class RefreshTokenValidator : AbstractValidator<RefreshRequest>
|
||||
{
|
||||
public RefreshTokenValidator()
|
||||
{
|
||||
RuleFor(r => r.RefreshToken)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace IdentityService.WebApi.Controllers.Auth
|
||||
{
|
||||
public class RegisterRequest
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string NickName { get; set; }
|
||||
}
|
||||
public class RegisterRequestValidator : AbstractValidator<RegisterRequest>
|
||||
{
|
||||
public RegisterRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.UserName)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
.MaximumLength(20)
|
||||
.MinimumLength(5);
|
||||
|
||||
RuleFor(r => r.Password)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
.MinimumLength(6)
|
||||
.MaximumLength(50);
|
||||
|
||||
RuleFor(r => r.NickName)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
.MaximumLength(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user