AuthController.cs 1.5 KB

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