Implement API security baseline (sys_user, JWT, audit fields, transactions, unique constraints) and Web real login with 401 handling. Document setup and development workflows in root, WmsLite.Api, and WmsLite.Web README files. Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using WmsLite.Api.Common;
|
|
using WmsLite.Api.Dtos.Auth;
|
|
using WmsLite.Api.Infrastructure.Auth;
|
|
using WmsLite.Api.Services.Interfaces;
|
|
|
|
namespace WmsLite.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class AuthController : ControllerBase
|
|
{
|
|
private readonly IAuthService _authService;
|
|
private readonly ICurrentUserContext _userContext;
|
|
|
|
public AuthController(IAuthService authService, ICurrentUserContext userContext)
|
|
{
|
|
_authService = authService;
|
|
_userContext = userContext;
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost("login")]
|
|
public async Task<ActionResult<BusinessResult>> Login([FromBody] LoginRequest request)
|
|
{
|
|
var result = await _authService.LoginAsync(request);
|
|
return Ok(BusinessResult.Ok(result));
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpGet("me")]
|
|
public ActionResult<BusinessResult> Me()
|
|
{
|
|
return Ok(BusinessResult.Ok(_authService.GetCurrentUser(_userContext)));
|
|
}
|
|
}
|