LoginSevice.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using SCADA.CommonLib;
  2. using SCADA.CommonLib.Data.DIL;
  3. using SCADA.CommonLib.Helper;
  4. using SCADA.CommonLib.Service;
  5. using System;
  6. using System.ComponentModel;
  7. namespace SCADA_DAQ.Customer.Service
  8. {
  9. /// <summary>
  10. /// 登录服务,提供用户登录
  11. /// </summary>.
  12. [DisplayName("登录服务")]
  13. public class LoginSevice : BaseService
  14. {
  15. private static LoginSevice _instance;
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. public static LoginSevice Instance { get => _instance ?? (_instance = new LoginSevice()); }
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. public override Type ConfigType => typeof(CustomerServiceConfig);
  24. /// <summary>
  25. ///
  26. /// </summary>
  27. public override ObservableObject ServiceConfig { get; set; }
  28. private LoginSevice()
  29. {
  30. if (_instance == null)
  31. {
  32. _instance = this;
  33. }
  34. }
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. /// <returns></returns>
  39. public override bool Start()
  40. {
  41. if (IsRunning) { return false; }
  42. RpcService.GetInstance().Regiseter(this); //将服务中方法注册到RPC服务器,可以给WebApi调用
  43. return base.Start();
  44. }
  45. /// <summary>
  46. ///
  47. /// </summary>
  48. public RpcResponse<object> GetLoginInfo(string token)
  49. {
  50. return new RpcResponse<object>()
  51. {
  52. IsSucceed = true,
  53. };
  54. }
  55. /// <summary>
  56. /// 用户登录
  57. /// </summary>
  58. /// <param name="userName">用户名</param>
  59. /// <param name="password">密码</param>
  60. public RpcResponse<object> UserLogin(string userName, string password)
  61. {
  62. if (AppRuntime.RuntimeInfo.GlobalDB is BaseDB db)
  63. {
  64. var res = db.UserLogin(userName, password);
  65. if (res.ReturnValue != null)
  66. {
  67. return new RpcResponse<object>()
  68. {
  69. IsSucceed = true,
  70. Data = new
  71. {
  72. UserId = ReflectionHelper.GetValueByPath(res.ReturnValue, "UserID_Str"),
  73. //Token = Guid.NewGuid(),
  74. Token = "admin-token"
  75. }
  76. };
  77. }
  78. else
  79. {
  80. return new RpcResponse<object>()
  81. {
  82. IsSucceed = false,
  83. Error = new Error() { Message = res.ErrorMessage }
  84. };
  85. }
  86. }
  87. return new RpcResponse<object>()
  88. {
  89. IsSucceed = false,
  90. Error = new Error() { Message = $"没有找到公共数据库" }
  91. };
  92. }
  93. }
  94. }