AuthController.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using ERP.Core.Dto;
  2. using ERP.Core.Interface;
  3. using ERP.Framework.Config;
  4. using ERP.Framework.Constants;
  5. using ERP.Framework.Emum;
  6. using ERP.Framework.Security;
  7. using ERP.Framework.WebApi;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Configuration;
  10. using Swashbuckle.AspNetCore.Annotations;
  11. namespace ERP.Core.Controllers
  12. {
  13. [Route("auth")]
  14. public class AuthController : BaseController
  15. {
  16. private readonly IConfiguration _configuration;
  17. private readonly IAuthService _authService;
  18. public AuthController(IConfiguration configuration, IAuthService authService)
  19. {
  20. _configuration = configuration;
  21. _authService = authService;
  22. }
  23. /// <summary>
  24. ///
  25. /// </summary>
  26. /// <param name="form"></param>
  27. /// <returns></returns>
  28. [HttpPost("login")]
  29. [SwaggerOperation(Description = "登录接口", Summary = "Login")]
  30. public IActionResult LoginAsync([FromBody] LoginBody form)
  31. {
  32. var securityConfig = _configuration.GetSection(FrameworkConstant.SECURITY_CONFIG).Get<SecurityConfig>() ?? new SecurityConfig();
  33. var loginUser = _authService.GetLoginUser(securityConfig, form.UserName, form.Password);
  34. var result = LoginHelper.LoginByDevice(loginUser, securityConfig, DeviceEnum.Web);
  35. //Todo 记录登录日志
  36. return Success(new
  37. {
  38. access_token = result,
  39. });
  40. }
  41. }
  42. }