123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using SCADA.CommonLib;
- using SCADA.CommonLib.Data.DIL;
- using SCADA.CommonLib.Helper;
- using SCADA.CommonLib.Service;
- using System;
- using System.ComponentModel;
- namespace SCADA_DAQ.Customer.Service
- {
- /// <summary>
- /// 登录服务,提供用户登录
- /// </summary>.
- [DisplayName("登录服务")]
- public class LoginSevice : BaseService
- {
- private static LoginSevice _instance;
- /// <summary>
- ///
- /// </summary>
- public static LoginSevice Instance { get => _instance ?? (_instance = new LoginSevice()); }
- /// <summary>
- ///
- /// </summary>
- public override Type ConfigType => typeof(CustomerServiceConfig);
- /// <summary>
- ///
- /// </summary>
- public override ObservableObject ServiceConfig { get; set; }
- private LoginSevice()
- {
- if (_instance == null)
- {
- _instance = this;
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public override bool Start()
- {
- if (IsRunning) { return false; }
- RpcService.GetInstance().Regiseter(this); //将服务中方法注册到RPC服务器,可以给WebApi调用
- return base.Start();
- }
- /// <summary>
- ///
- /// </summary>
- public RpcResponse<object> GetLoginInfo(string token)
- {
- return new RpcResponse<object>()
- {
- IsSucceed = true,
- };
- }
- /// <summary>
- /// 用户登录
- /// </summary>
- /// <param name="userName">用户名</param>
- /// <param name="password">密码</param>
- public RpcResponse<object> UserLogin(string userName, string password)
- {
- if (AppRuntime.RuntimeInfo.GlobalDB is BaseDB db)
- {
- var res = db.UserLogin(userName, password);
- if (res.ReturnValue != null)
- {
- return new RpcResponse<object>()
- {
- IsSucceed = true,
- Data = new
- {
- UserId = ReflectionHelper.GetValueByPath(res.ReturnValue, "UserID_Str"),
- //Token = Guid.NewGuid(),
- Token = "admin-token"
- }
- };
- }
- else
- {
- return new RpcResponse<object>()
- {
- IsSucceed = false,
- Error = new Error() { Message = res.ErrorMessage }
- };
- }
- }
- return new RpcResponse<object>()
- {
- IsSucceed = false,
- Error = new Error() { Message = $"没有找到公共数据库" }
- };
- }
- }
- }
|