GoViewSysService.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // 大名科技(天津)有限公司 版权所有
  2. //
  3. // 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
  4. //
  5. // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动
  6. //
  7. // 任何基于本项目二次开发而产生的一切法律纠纷和责任,均与作者无关
  8. namespace Admin.NET.Plugin.GoView.Service;
  9. /// <summary>
  10. /// 系统登录服务
  11. /// </summary>
  12. [UnifyProvider("GoView")]
  13. [ApiDescriptionSettings(GoViewConst.GroupName, Module = "goview", Name = "sys", Order = 500)]
  14. public class GoViewSysService : IDynamicApiController
  15. {
  16. private readonly SysAuthService _sysAuthService;
  17. private readonly SqlSugarRepository<SysUser> _sysUserRep;
  18. private readonly SysCacheService _sysCacheService;
  19. public GoViewSysService(SysAuthService sysAuthService,
  20. SqlSugarRepository<SysUser> sysUserRep,
  21. SysCacheService sysCacheService)
  22. {
  23. _sysAuthService = sysAuthService;
  24. _sysUserRep = sysUserRep;
  25. _sysCacheService = sysCacheService;
  26. }
  27. /// <summary>
  28. /// GoView 登录
  29. /// </summary>
  30. /// <returns></returns>
  31. [AllowAnonymous]
  32. [DisplayName("GoView 登录")]
  33. public async Task<GoViewLoginOutput> Login(GoViewLoginInput input)
  34. {
  35. _sysCacheService.Set(CommonConst.SysCaptcha, false);
  36. input.Password = CryptogramUtil.SM2Encrypt(input.Password);
  37. var loginResult = await _sysAuthService.Login(new LoginInput()
  38. {
  39. Account = input.Username,
  40. Password = input.Password,
  41. });
  42. _sysCacheService.Remove(CommonConst.SysCaptcha);
  43. var sysUser = await _sysUserRep.AsQueryable().ClearFilter().FirstAsync(u => u.Account.Equals(input.Username));
  44. return new GoViewLoginOutput()
  45. {
  46. Userinfo = new GoViewLoginUserInfo
  47. {
  48. Id = sysUser.Id.ToString(),
  49. Username = sysUser.Account,
  50. Nickname = sysUser.NickName,
  51. },
  52. Token = new GoViewLoginToken
  53. {
  54. TokenValue = $"Bearer {loginResult.AccessToken}"
  55. }
  56. };
  57. }
  58. /// <summary>
  59. /// GoView 退出
  60. /// </summary>
  61. [DisplayName("GoView 退出")]
  62. public void GetLogout()
  63. {
  64. _sysAuthService.Logout();
  65. }
  66. /// <summary>
  67. /// 获取 OSS 上传接口
  68. /// </summary>
  69. /// <returns></returns>
  70. [AllowAnonymous]
  71. [ApiDescriptionSettings(Name = "GetOssInfo")]
  72. [DisplayName("获取 OSS 上传接口")]
  73. public static Task<GoViewOssUrlOutput> GetOssInfo()
  74. {
  75. return Task.FromResult(new GoViewOssUrlOutput { BucketURL = "" });
  76. }
  77. }